Given a class Window, with integer data members width, height, xPos, and yPos, write the following two constructors: - a constructor accepting 4 integer arguments: width, height, horizontal position, and vertical position (in that order), that are used to initialize the corresponding members. - a constructor accepting 2 integer arguments: width and height (in that order), that are used to initialize the corresponding members. The xPos and yPos members should be initialized to 0.
I only need help with the interface for public, this is my code so far:
Window (int width1, int height1, int horizontal1, int vertical1)
{
}
Reading what you posted that is what you wanted. One constructor that accepts 4 parameters, and one that accepts two. If I am to use default parameters nothing was stated.
And the constructor are overloaded the way you specified. If you don't know what overloading in C++ means learn a little more
Yea it asks for a partial coding not the whole program, I know what overloading means, the submission keeps marking it wrong, and I cant think of any other way to write the code for it.
That is because that code is not 'initializing' the members, it is assigning the member after they have already been initialized. If you want to initialize you have to use the member initialization list, I wont post the code unless you get stuck but look up 'member initialization list'.
Louflow, if you believe that you've received your answer, please mark the thread as solved. If not, could you please post the relevant code so that we can offer you further advice. No rudeness intended.
Azagaros, the code you posted doesn't require a destructor. The default destructor would do just fine. Just thought you'd like to know.
Based on the code you gave, I can only suggest that you use the initialisation list, but that's already been suggested. Can you post the full code, because it's obviously not an issue with the constructors.