1, 2 questions are displayed, 3 questions are corrected
1.
# Include < Stdio. h >
# Include < Stdlib. h >
Class A {
Public :
A () {func ( 0 );}
Virtual Void Func ( Int Data) {printf ( " A1: % d \ n " , Data );}
Virtual Void Func ( Int Data) Const {Printf ( " A2: % d \ n " , Data );}
Void Func ( Char * Str) {printf ( " A3 :( % s) \ n " , STR );}
};
Class B: Public A {
Public :
Void Func () {printf ( " B1: % s \ n " , "" );}
Void Func ( Int Data) {printf ( " B2: % d \ n " , Data );}
Void Func ( Char * Str) {printf ( " B3 :( % s) \ n " , STR );}
};
IntMain ()
{
A*Pa;
B;//A1: 0
ConstA*PCA;
Pa = & B;
Pa -> Func ( 1 ); // B2: 1
Pa -> Func ( " Test " ); // A3 :( test)
A (). func ( 1 ); // A1: 0 A1: 1
PCA = & B;
PCA -> Func ( 2 ); // A2: 2
System ( " pause " );
return 0 ;
}
2.# Include<Iostream>
Using NamespaceSTD;
Template < Typename t >
Void Func ( Const Int & T)
{
Cout < T + 100 < Endl;
}
Template<Typename t>
VoidFunc (ConstT&T)
{
Cout<T<Endl;
}
Int Main ()
{
Func ( 10.3 ); // 10.3
Func ( 1000 ); // 1000
System ( " Pause " );
Return 0 ;
}
The first template function does not include type parameters, so it cannot perform template deduction or instantiate.
An error occurs even if it is changed to the following.# Include<Iostream>
Using NamespaceSTD;
Template < Typename t >
Void Func ( Const Int & T)
{
Cout < T + 100 < Endl;
} // This function actually does not support template deduction.
// Template <typename T>
// Void func (const T & T)
// {
// Cout <t <Endl;
// }
Int Main ()
{
// Func (10.3 ); // 10.3
Func ( 1000 ); // 1000
System ( " Pause " );
Return 0 ;
}
no matching function for call to 'func (INT) '
3. # include iostream >
# include stdlib. h >
using namespace STD;
ClassKlass
{
Public:
Klass () {cout< "Ctor called!";}
Private :
~ Klass (){} // !!! Private
Void Func ( Int N)
{
Cout < " Klass !! " < Endl;
}
Public:
VoidTest ()
{
Func (100);
}
};
int main ()
{< br> Klass K;
K. test ();
//Automatically call ~ Kclass () Here, but private!
System ("Pause");
Return 0;
}