I am stuck trying to write my first class. I have no idea if this is correct or not. I have it working like it is and it prints out what I put in, but I need to have default parameters in the constructor and when I do this it doesn't work anymore. Does the constructor w/ default params go up in the class or in the main like I have my object? Take a look and help me out I have an online class and no one to bounce ideas off.
It's because of the names of your constructor arguments I think. You cannot name them the exact same names as the members of your class. That would cause name collision in the constructor body. In addition you do not actually end up defining the constructor at any point in your program.
EDIT: By the way, Dev ftf. Use wxdev instead if anything: http://www.cplusplus.com/forum/articles/7263/
I tried to take the parameter names out, no luck. Tried adding s to the end of them to make them unique, no luck. I Also tried w/ no names like this:
secretType secretObject(string = " ", int = 0, int = 0, double = 0); still no luck.
So, I have the constructor in the right place but just wrote it wrong? How do you make this work w/ the default parameters? I am still stuck.
secretType secretObject(string = " ", int = 0, int = 0, double = 0);
This is not a constructor declaration but a function declaration called secretObject that returns an object of type secretType
a constructor declaration would look like this: secretType(string str, int a, int b, double c);