how many constructor this class have?

class C
{
public:

C();
C(int);
C(float);
C(int, float);
private:
int nNum;
float fNum;
};

C myC ;
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.:
1
2
3
C::C(){
   //code
}


I forget to this a lot, so just warning you so you don't make it.
Last edited on
C actually has 6 constructors. The four explicitly declared and the implicitly declared copy and move constructors.
Copy and Move constructors? What do they do? I haven't used constructors much
Last edited on
Topic archived. No new replies allowed.