Problems needing attention in constructor string under Linux

Source: Internet
Author: User

/* 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

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.