in the main section, i just wrote:
person p;
and there are errors. can you please explain me why? doesnt it suppose to
be created with the parametered ctor?
You didn't post all of your code or any of your errors, so I can't see where you went wrong, but here is a working example of a constructor with default values for parameters:
First of all- thank you for your investment!
and sorry. i add it below. can you please explain me why it doesnt work?
i didnt learn string yet..
H file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#define PERSON_H
class person
{
public:
char *_name;
int _age;
bool _isMale;
person(char*,int,bool);
~person(void);
char* getName() const;
int getAge() const;
bool getSex() const;
};
When asked to be more specific about "what does not work", that means if you're getting compile errors, post the exact text of the compile errors. If you're getting run time errors, post what errors you're getting at run time. Don't just repeat "it doesn't work".
As I explained above, default parameters go in the declaration, not the implementation. I see you added the default values in the declaration of the person constructor, but you have not removed them from the implementation. I already gave you the corrected code for the implementation of the constructor.
Your include guard is still not correct. See the example I posted.
You also have a problem with how you're passing name into your constructor. You're passing a pointer to a char array, then storing that pointer in your class. What happens if the pointer to the char array goes out of scope? Your copy of that pointer is now invalid.