ChinaUnix.net
相关文章推荐:

拷贝构造函数

各位大侠,小弟今天遇到个问题: 我打算看看private拷贝构造函数能不能在类定义内部使用的问题,或者是去证实它。 有一个叫做show_val_ref的函数,采用值传递的方式,我的本意是希望调用private拷贝构造,可惜结果不是想要的,并没有执行拷贝构造! 代码如下: #include using namespace std; class cntor { public: explicit cntor(int a){cout<<"in the defaut constructor!"<

by hawtriks - C/C++ - 2011-09-02 15:53:08 阅读(2523) 回复(8)

相关讨论

我在书上看了一段代码,对程序运行结果有点疑惑,请高手帮忙分析一下: #include ; #include ; class Student { public: student(char * pName="no name") { cout<

by shaquillewang - C/C++ - 2004-09-24 15:24:11 阅读(779) 回复(2)

当通过一个类的对象去初始化另一个类对象时,调用拷贝构造函数,如果没有定义拷贝构造函数则调用默认的, 那么,函数结束时,是不是也得调用该类的析构函数啊??

by kewenliang - C/C++ - 2008-08-24 19:23:24 阅读(2704) 回复(15)

默认的拷贝构造函数的函数体 是不是也和默认的构造函数的函数体一样,都是空的?

by laye - C/C++ - 2003-12-21 09:49:13 阅读(800) 回复(1)

[code]class Person { public: Person(){cout << "construct"<< endl;} Person(const Person& p1) { cout << "copy" << endl; } }; Person fun() { Person p1; return p1; } int main() { fun(); return 0; }[/code]为啥 不调用 拷贝构造函数,很奇怪 可是如果 fun 函数 写成这样[code]Person fun() { Person *p1 = new Person; return *p1; }[/code]就调用了,这尼玛 奇怪的

by homerzhou - C/C++ - 2014-01-17 14:55:35 阅读(2852) 回复(6)

#include #include #include using namespace std; class num { public: num(){n=1;cout << "构造函数执行" << endl;} num(int i) { n=i; cout << "带参数的构造函数执行" << endl; } num(const num &tmp){this->n = tmp.n; cout << "拷贝构造函数执行" << endl;} ~num(){cout << "析构函数执行" << endl;} int get(void)const{return n;} void set(int x){n = x;} void add(void){n++...

by robotke - C/C++ - 2012-04-29 09:41:33 阅读(2071) 回复(4)

gdb显示堆栈如下: #0 0xffffe410 in __kernel_vsyscall () #1 0xb7d29a30 in raise () from /lib/libc.so.6 #2 0xb7d2b153 in abort () from /lib/libc.so.6 #3 0xb7f114b0 in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/libstdc++.so.6 #4 0xb7f0eed5 in ?? () from /usr/lib/libstdc++.so.6 #5 0xb7f0ef12 in std::terminate() () from /usr/lib/libstdc++.so.6 #6 0xb7f0f04a in __cxa_throw () ...

by hiliunx - C/C++ - 2011-09-27 10:54:38 阅读(4772) 回复(3)

请不考虑程序的合理性 class A; A produceA() { A temp; return temp; } A a = produceA(); //该句会不会调用拷贝构造函数 /////////////////////////////////////////////////// 如果是下面这句呢 class A; A& produceA() { A temp; return temp; } A a = produceA(); //该句会不会调用拷贝构造函数 请不要考虑函数合理性,第二个用引用确实有问题,大家忽略之

by czijian - C/C++ - 2010-01-14 17:21:58 阅读(1418) 回复(3)

代码如下: #include using namespace std;   class A {     private:         int i;     public:         A(){}         A(const A& a){ cout << "copy constructor" << endl; } /* 构造1 */       &nbs...

by zpp71 - C/C++ - 2009-07-28 13:32:25 阅读(1913) 回复(9)

class A { public: A(const A& a); private: int x; }; A::A(const A& a) { x = a.x; //??? x是private怎么能访问 }

by talent_t - C/C++ - 2009-05-19 16:13:09 阅读(2512) 回复(7)

代码如下: [code] class test { public: test() { cout<<"call test"<

by disheng727 - C/C++ - 2009-04-05 08:10:09 阅读(1197) 回复(3)