Class definition Object array

Source: Internet
Author: User
Tags class definition

1. class definition;
2. Array of objects

#include <iostream>
using namespace std;
class myfoo
{
private:
    int num;
    string foostr;
    
public:
    myfoo(int a,std::string& str ):num(a),
foostr(str)
        {           
            cout << "myfoo construt : " << num << endl;
        }

    myfoo()  //myfoo aSmple;如果自己写了构造函数,那么需要列出默认构造

            //  functions
         {
       }
    ~ Myfoo ()
        {
             cout <<  "Myfoo destrut:"  << endl;
        }
};
Int main (int argc, char* [])
{

    string strtmp ("I_love" );

    myfoo G[3] = {myfoo (1,strtmp), Myfoo (2,strtmp), Myfoo (3,strtmp)};
    return 0;
}



3.
Foo.cpp:29:error:no matching function for call to ' Myfoo::myfoo (int, const char [4]) '
Foo.cpp:15:note:candidates Are:myfoo::myfoo ()
Foo.cpp:11:note:myfoo::myfoo (int, std::string&)
Foo.cpp:5: Note:myfoo::myfoo (const myfoo&)

};

Class definition Object array

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.