#include
Using STD: : cout;
Using STD: : endl;
Template
Class A
{
Private:
int a;
Public:
Friend void show2 & lt; T> (A
};
The template class A
Int main (void)
{
return 0;
}
Results: the error
Program 2:
#include
Using STD: : cout;
Using STD: : endl;
Template
Class A
{
Private:
int a;
Public:
Friend void show2 & lt; T> (A
};
//the template class A
Int main (void)
{
return 0;
}
Results: no error
Is the difference between the two procedures: there are explicit instantiation is an error, otherwise we are not an error, what reason is this?
CodePudding user response:
Your explicit instantiation grammar is wrong?CodePudding user response:
Both are wrong, the second is not an error because you haven't instantiateTemplate class a friend is such statement
# include
#include
using namespace std;
Template
Class A
{
Private:
int a;
Public:
A () {}
Template
Friend void show2 (A& amp;);
};
Template
Void show2 (A& Hf)
{
STD: : cout & lt;}
Template<>
The class A{
Double a;
Public:
(A) {A=0; }
Template
Friend void show2 (A& amp;);
};
Int main (void)
{
AA1.
Show2 (a1);
return 0;
}