level 10
今天写了一个简单的类,代码如下:
class student
{
public:
int number;
int score;
};
然后用这个类定义一个对象,结果在student s1( 这个时候系统提示了一个构造函数:
student(const student &);求问就我上面的类student而言,这么写C++默认提供了多少成员函数?
2012年11月06日 09点11分
1
level 8
一个默认构造函数student::student(),一个析构函数student::~student(),另外不知道会不会提供默认赋值的函数,乱说的
2012年11月06日 09点11分
3
其实我没太搞明白析构函数用来干嘛的,求指教- -我除了释放这个类基本不用析构的这个,有时候释放也不用
2012年11月06日 09点11分
回复 无极神原 :析构函数当然是用来销毁对象的啊,无论你是不是自己定义析构函数,系统的析构函数都在对象使用完毕后销毁对象,对于自己定义的析构函数,只是自己想在销毁对象时定义一些自定义的行为而已,但系统默认的析构函数不被屏蔽
2012年11月06日 09点11分
回复 无极神原 :反观默认构造函数,如果自定义了构造函数,那么默认构造函数就被屏蔽了,这也许是构造函数和析构函数在自定义后的最大却别了
2012年11月06日 09点11分
回复 weishusen520 :soga谢谢了
2012年11月06日 09点11分
level 8
当一个类里什么都不写的时候, 在声明的过程且当这些函数需要被调用时,它们才会被编译器创建出来。
有: 默认构造函数、默认析构函数、 默认拷贝构造函数、 默认重载操作符。
2012年11月06日 11点11分
5
回复 挂羊头卖犬肉 : 哪里敢当, 我来拜你
(坏淫)
2012年11月08日 13点11分
level 12
ISO/IEC C++ N3376
12 Special member functions
1 The
default constructor (12.1),
copy constructor and
copy assignment operator (12.8),
move constructor
and
move assignment operator (12.8), and
destructor (12.4) are special member functions. [ Note:
The
implementation will implicitly declare these member functions for some class types when the program does
not explicitly declare them. The implementation will implicitly define them if they are odr-used (3.2).
See 12.1, 12.4 and 12.8. —end note ] Programs shall not define implicitly-declared special member functions.
2012年11月06日 14点11分
6