Mar 24, 2014 at 5:22pm
class C
{
public:
C();
C(int);
C(float);
C(int, float);
private:
int nNum;
float fNum;
};
C myC ;
Mar 24, 2014 at 5:31pm
You can have any amount of constructors in a class - as long as they have different parameters - and in this case, you have 4:
1 2 3 4
|
C();
C(int);
C(float);
C(int, float);
|
|
Just remember when you write the constructor, to put the class name behind it, i.e.:
I forget to this a lot, so just warning you so you don't make it.
Last edited on Mar 24, 2014 at 5:31pm
Mar 24, 2014 at 7:04pm
C actually has 6 constructors. The four explicitly declared and the implicitly declared copy and move constructors.
Mar 24, 2014 at 11:08pm
Copy and Move constructors? What do they do? I haven't used constructors much
Last edited on Mar 24, 2014 at 11:22pm