struct mystruct
{
int i;
float f;
}
mystruct ms;
ms i = 45
ms f = 22.6
Then i am to convert my struct into a class name peep by making the data members be private and by adding public members function to set the values of the data membered and to get the vales.
class peep{
private:
int i;
float f;
public:
int get i (void);
f;pat get f (void);
}// end of class
int peep:: get i (void)
{
i = 45;
return i;
}
float peep::get f (void)
{f = 22.6
return f;
}
my friend say the i = 45 and f = 22.6 have some problem at the end and i dont' undersatnd what he is saying. Can anyone explain it to me?
There are many problems with your class:
* get i ( and get f ) are not valid identifiers ( there's a space in the name )
* getter functions should be const
* you are modifying the values of the members inside the getters
* to initialize the class you should add a constructor