This example describes the use of C + + architecture. Share to everyone for your reference. The specific analysis is as follows:
C + + architecture provides more functionality than C-struct, such as default constructors, copy constructors, operator overloads, which make it easy for struct objects to pass values.
For example, I define a simple structure and then use it as a vector element type, so you need to implement these three functions, otherwise you can only use pointers.
Copy Code code as follows:
#include <iostream>
#include <vector>
using namespace Std;
struct ST
{
int A;
int b;
ST ()//default constructor
{
A = 0;
b = 0;
}
void set (st* s1,st* s2)//Assignment function
{
S1->a = s2->a;
S1->b = s2->b;
}
st& operator= (const st& s)/overloaded operator
{
Set (this, (st*) &s)
}
ST (const st& s)//copy constructor
{
*this = s;
}
};
int main ()
{
ST A; Calling the default constructor
Vector<st> v;
V.push_back (a); Calling the copy constructor
ST s = v.at (0); Call = function
cout << S.A << "" << s.b << Endl;
Cin >> A.A;
return 0;
}
I hope this article will help you with the C + + program design.