My Program
Nov 28, 2011 at 1:04am UTC
Well this is one of the first few programs i have tried to write and i was wondering what's wrong with it, i know it may be a very obvious problem but i'm new to C++ and don't have a eye for catching errors on the spot yet.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#include <iostream>
#include <string>
using namespace std;
class MyClass
{
public :
void setName(string x)
{
name = x;
}
string getName()
{
return name;
}
private :
string name;
}
int main()
{
MyClass myObject;
myObject.setName = ("Sir Noob Face" );
cout << myObject.getName();
return 0;
}
Nov 28, 2011 at 1:07am UTC
missing semicolon after the class definition (line 20).
There is also an error on line 26. the =
shouldn't be there.
Last edited on Nov 28, 2011 at 1:08am UTC
Nov 28, 2011 at 1:09am UTC
Line 26:
Incorrect function call.
Change to
myObject.setName("Sir Noob Face" );
Nov 28, 2011 at 1:12am UTC
Oh i see now, much appreciated.
Topic archived. No new replies allowed.