Okay, I have been learning about using classes, now I want to write my own.
I read how to do it in various textbooks and this is what I came up with:
Now I know the class definition is usually in a seperate file which is included, but it's meant to work like this too isn't it?Code:#include <iostream.h> #include <stdlib.h> class Myclass { public: Myclass() { value = 0; } Myclass(int x) { vlaue = x; } void print() { cout<<value; } void set(int x) { value = x; } private: int value; }; void main() { int number; Myclass test; test.print(); cout<<"Enter a new value: "; cin>>number; test.set(number); test.print(); cin.get(); }
When I try to complile this code in Bloodshed Dev-C++ I get an error at the line
telling meCode:value = 0;
What's wrong?9 h:\myclass.cpp `value' undeclared (first use this function)
Am I totally ont he wrong track or is it just a typo or small syntax error?