/* In the following program, two constructors are set in the named class, and strings are received as string and char*, and when the setting shown in n is constructed as a string, the constructor of the string argument is invoked, and the string is passed directly in M. is called the char* construct,
In some C + + textbooks, it is possible for the compiler to make a direct use of string constants to construct the behavior of the call string constructs, and in g++ compiled under the test to adopt char* constructs, need to pay attention to this small problem * *
1#include <iostream>2#include <stdlib.h>3 using namespacestd;4 5Template <typename t>6 7 classnamed8 {9 stringname;Ten T N; One Public: ANamedConst Char* CH,Constt&b) - { -Name =ch; then =b; -cout<<"called char*"<<Endl; - } -Named (Const string& STR,ConstT &b) + { -Name =str; +n =b; Acout<<"called string"<<Endl; at } - voidprint () - { -cout<<name<<Endl; -cout<<n<<Endl; - } in - }; to + intMain () - { the stringNam ="Hello"; *Named <int> N (NAM, +); $Named <int> m ("Hello AAA", +);Panax Notoginseng n.print (); - m.print (); the}
Output of the program:
StringChar*Hellotriple Hello aaa------------------ 0returncontinue
Problems needing attention in constructor string under Linux