Home > Back-end >  Small white about c template class related issues
Small white about c template class related issues

Time:01-27

Excuse me, the parameters of the template class in c + + is can write their own class? His definition of class A, B, inside member functions and variables must be consistent? Why is that?
For example,
Class A
{
Public:
Int test ();
.
Private:
Int qwe;
.

}
Class B
{
Public:
Int test ();
.
Private:
Int qwe;
.

}
A a;
B B;
The text (a, y);
.
The text (b, y);
Template
BOOL text (T & amp; X, short & amp; Y)
{
.
}















CodePudding user response:

Can be customized

CodePudding user response:

Passing parameters (class) can be customized, do not need to remain consistent

CodePudding user response:

Thanks to answer
Isn't as long as the guarantee in the realization of the template class x as the functions and variables involved in class A and class B and consistent is ok? The rest of class A class B member functions and variables if you can't have A consistent? If A member function in the class A, class B no, call this function in the realization of the template class, compile all fail? (I tried is not through, but not sure, why can be found at compile time error? Because the process of compiling the a and b as parameters has handed in? I thought it would be in the process of debugging, when b as parameters in just complains, can tell me why compile will go wrong? (the realization of the template class written in the book. H file, want to try to write in. CPP file, try the online method is not successful, may be where I write wrong))

In the

Template
BOOL text (T & amp; X, short & amp; Y)
{
.
}
  • Related