How to initialize object in constructor?# Programming - 葵花宝典
r*r
1 楼
One rule for constructor:use initialization instead of assignment. Is this
also true for object?For example,I have a simple class
Point{
public:
...
private:
float x;
float y;
}
Suppose I have another class and want to use a point as a private member,
PointColl{
public:
//default constructor
PointColl();
PointColl(const PointColl & thePoint);
...
private:
int number;
Point* thePointer;
}
For the default constructor, can I do like this
PointColl::PointColl():number(0)
{
thePointer = n
also true for object?For example,I have a simple class
Point{
public:
...
private:
float x;
float y;
}
Suppose I have another class and want to use a point as a private member,
PointColl{
public:
//default constructor
PointColl();
PointColl(const PointColl & thePoint);
...
private:
int number;
Point* thePointer;
}
For the default constructor, can I do like this
PointColl::PointColl():number(0)
{
thePointer = n