1.类定义;
2.对象数组
#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; 如果自己写了构造函数,那么需要列出默认构造
// 函数 { } ~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&)
};