//class definition
class account
{
friend Date;
private:
int month;
public:
int print_dob();
account();
}; //end class
account::account()
{
month=6;
Date date1(6, month, 1972);
}
void account::print_dob()
{
date1.print();
}
The following code won't work because date1 is an undeclared identifier to member function print_dob(). Is there anyway to have print_dob() only run if if the constructor has been called first? You know what I mean?
Did the constructor run yet???
Do you mean for 'date1' to be local to the constructor? Also, why do the two print_dob()'s have different return types?
well, if you wanted it to run right after the constructor has been called, you could call the method at the last line, after all of the member variables have been initialized:
Is this what you had in mind?
account::account(){ month=6; Date date1(6, month, 1972); print_dob();}
Is this what you had in mind?
I think I see what you are trying to say. Try adding date1 as a private member variable and then instantiate date1 within your constructor.
There's no date1 object inside your class. You need to have one there in order for it to be accessed by the whole class, not just that function.
I have to have the date1 instance in the constructor...So is there anyway to tell the compiler that print_dob can't be called unless the constructor has already been called??? thanks for youre help!!! :)
Quote:Original post by marcmassacreWhy? (Homework?)
I have to have the date1 instance in the constructor...
//class definitionclass account{ friend Date; Date* date1; private: int month; public: int print_dob(); account(); }; //end class account::account(){ month=6; Date temp = new Date(6, month, 1972); date1 = &temp;}void account::print_dob(){date1->print();}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement