Hello. I'm a new c++ user after having used Java for a few years as well as php. I'm having trouble with strings and how they can be used with classes.
This is what my runner.h file looks like
#include <string>
#include "TestApp1.h"
#ifndef RUNNER_H
using namespace std;
class Runner{
Private:
string m_name;
int m_time;
int m_age;
int m_rank;
Runner() {} //private default constructor
Public:
Runner(string name,int time,int age,int rank);
void setRunner(string name,int time,int age, int rank);
int getName() { return m_name; }
int getTime() { return m_time; }
int getAge() { return m_age;}
int getRank() { return m_rank;}
};
#endif
and this is what my runner.cpp file looks like:
#include <string>
#include "TestApp1.h"
#include "Runner.h"
using namespace std;
//Runner Constructor
Runner::Runner(string name, int time,int age, int rank)
{
setRunner(name,time,age,rank);
}
//Runner Member Function
void Runner::setRunner(string name, int time,int age,int rank)
{
m_name = name;
m_time = time;
m_age = age;
m_rank = rank;
}
My problems is that I'm trying to use a string as a private data member for this runner class. But the compiler refuses to even see it. I'm sure my class files have some errors in them but at the moment I just want the compiler to read the string. Anyone have any ideas? And I'm using visual c++ 2008 express edition.
And here are some compiler errors for anyone interested:
1>c:\visual studio 2008\projects\testapp1\testapp1\runner.h(8) : error C2275: 'std::string' : illegal use of this type as an expression
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xstring(2210) : see declaration of 'std::string'
1>c:\visual studio 2008\projects\testapp1\testapp1\runner.h(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\visual studio 2008\projects\testapp1\testapp1\runner.h(8) : error C2146: syntax error : missing ';' before identifier 'm_name'
1>c:\visual studio 2008\projects\testapp1\testapp1\runner.h(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\visual studio 2008\projects\testapp1\testapp1\runner.h(16) : error C2275: 'std::string' : illegal use of this type as an expression
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xstring(2210) : see declaration of 'std::string'
1>c:\visual studio 2008\projects\testapp1\testapp1\runner.h(16) : error C2146: syntax error : missing ')' before identifier 'name'
1>c:\visual studio 2008\projects\testapp1\testapp1\runner.h(16) : error C2056: illegal expression
1>c:\visual studio 2008\projects\testapp1\testapp1\runner.h(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\visual studio 2008\projects\testapp1\testapp1\runner.h(19) : error C2065: 'm_name' : undeclared identifier
1>c:\visual studio 2008\projects\testapp1\testapp1\runner.cpp(8) : error C2511: 'Runner::Runner(std::string,int,int,int)' : overloaded member function not found in 'Runner'
1> c:\visual studio 2008\projects\testapp1\testapp1\runner.h(6) : see declaration of 'Runner'
1>c:\visual studio 2008\projects\testapp1\testapp1\runner.cpp(16) : error C2065: 'm_name' : undeclared identifier