Collect TrendMicro pen questions

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.