Author Topic: MinGW compiler error with string class in C++  (Read 6323 times)

Offline surrender

  • Single posting newcomer
  • *
  • Posts: 2
MinGW compiler error with string class in C++
« on: September 16, 2010, 11:17:25 am »
 :?
Hell all,

I made a class declaration in a .h file with a private data member 'string name'.
After compilation of the corresponding .cpp file I keep getting the following errors:

line 17: "string does not name a type"
line 19: "expected ')' before 's' "

code snippet follows below: (in .h file)

#include <string>

        class Animal
       {
       protected:
17:      string name;
       public:
19:      Animal(string s){name = s;};
           ~Animal(){};    
           // Member functions
           void Eat();  
           void Drink();
           void Sleep();
           void Walk();

       };

What could be the possible cause of these errors?
I have changed the compilker settings in Code::Blocks, but it still leaves me
with the same errors.
Any help I will appreciate!

Thanks,

surrender
« Last Edit: September 16, 2010, 11:19:39 am by surrender »

Offline nenin

  • Almost regular
  • **
  • Posts: 212
Re: MinGW compiler error with string class in C++
« Reply #1 on: September 16, 2010, 11:20:42 am »
You forget about namespace std.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: MinGW compiler error with string class in C++
« Reply #2 on: September 16, 2010, 11:29:08 am »
Not related to C::B.
General programming questions are not allowed and should not be answered in our forum/website.

Please ask such a question in a C/C++-forum next time.

Topic locked !