Struct and Class

OK first of all here's the struct
1
2
3
4
5
6
7
8
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.

And here's what i wrote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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

Read http://www.cplusplus.com/doc/tutorial/classes/
Topic archived. No new replies allowed.