hey all!
this might look silly but i'm having problems using strings in a custom class.
here is the code:
word.h
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#ifndef WORD_H
#define WORD_H
class Word
{
public:
Word( string );
string get( void );
private:
string i;
};
#endif
|
word.cpp
1 2 3 4 5 6 7 8 9 10 11 12
|
#include "word.h"
#include <string>
Word::Word(string ii)
{
i = ii
}
string Word::get( void )
{
return i;
}
|
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include "word.h"
#include <string>
#include <iostream>
using namespace std;
int main()
{
Word c( "3" );
cout << c.get();
cin.get();
}
|
and here are the lovely errors:
Error 1 error C2460: 'Word::string' : uses 'Word', which is being defined word.h 7
Error 2 error C2146: syntax error : missing ';' before identifier 'get' word.h 8
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int word.h 8
Error 4 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int word.h 8
Warning 5 warning C4183: 'get': missing return type; assumed to be a member function returning 'int' word.h 8
Error 6 error C2146: syntax error : missing ';' before identifier 'i' word.h 10
Error 7 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int word.h 10
Error 8 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int word.h 10
Error 9 error C2440: 'initializing' : cannot convert from 'const char [2]' to 'Word' main.cpp 9
Error 10 error C2460: 'Word::string' : uses 'Word', which is being defined word.h 7
Error 11 error C2146: syntax error : missing ';' before identifier 'get' word.h 8
Error 12 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int word.h 8
Error 13 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int word.h 8
Warning 14 warning C4183: 'get': missing return type; assumed to be a member function returning 'int' word.h 8
Error 15 error C2146: syntax error : missing ';' before identifier 'i' word.h 10
Error 16 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int word.h 10
Error 17 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int word.h 10
Error 18 error C2597: illegal reference to non-static member 'Word::string' word.cpp 4
Error 19 error C2146: syntax error : missing ')' before identifier 'ii' word.cpp 4
Error 20 error C2761: '{ctor}' : member function redeclaration not allowed word.cpp 4
Error 21 error C2059: syntax error : ')' word.cpp 4
Error 22 error C2143: syntax error : missing ';' before '{' word.cpp 5
Error 23 error C2447: '{' : missing function header (old-style formal list?) word.cpp 5
Error 24 error C2143: syntax error : missing ';' before 'Word::get' word.cpp 9
Error 25 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int word.cpp 9
Error 26 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int word.cpp 10
Error 27 error C2065: 'i' : undeclared identifier word.cpp 11
can anyone make sense of these errors and why they are occurring? everything looks fine to me syntactically. am i missing includes in the word.h file?
thanks!