I am an experienced programmer using pascal with borlands delphi IDE and have recently took it upon myself to start to learn C. I have so far been able to figure out how to do things using google and some books. I am however at a loss for the following.
In delphi I could easily create a custom class using the class keyword and despite seaching for custom class and object related tutorials and exmpales on the internet I still have no idea how to wite a custom class. The following is a small test example I am trying to get working:
when I try to compile it using gcc I get:Code:#include <stdio.h> class MyClass { public: MyClass(int num) { setNum(num); } void setNum(int num) { number = num; } int getNum() { return number; } private: int number; }; main() { int a; MyClass myc1(3); a = myc1.getNum(); printf("the number is %d\n", a); }
I guess this may be a trivial thing for most c programmers but any help would be greatly appreciated and more importantly lower my blood pressure. . Thankstmp.c:4: parse error before "MyClass"
tmp.c:4: warning: data definition has no type or storage class
tmp.c:6: parse error before "MyClass"
tmp.c:7: syntax error before '{' token
tmp.c: In function `setNum':
tmp.c:16: `number' undeclared (first use in this function)
tmp.c:16: (Each undeclared identifier is reported only once
tmp.c:16: for each function it appears in.)
tmp.c: In function `getNum':
tmp.c:21: `number' undeclared (first use in this function)
tmp.c: At top level:
tmp.c:23: parse error before ':' token
tmp.c: In function `main':
tmp.c:30: parse error before "myc1"
tmp.c:32: `myc1' undeclared (first use in this function)