Very Frustrating Errors

I'm using Code::Blocks to make a command line program. Whenever I try to compile I get a "using-declaration for non-member at class scope" error. I have two classes in my program so far. Only one of them generates this error. Here's the code before I continue.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//AnEvent.h
#ifndef ANEVENT_H
#define ANEVENT_H

class AnEvent
{
    public:
        AnEvent();
        virtual ~AnEvent();

    protected:
    private:
        std::string object;//this line gives me the error
};

#endif // ANEVENT_H 


I've tried searching many forums for answers, but most of those were solved by replacing "String" with "string" or "string" with "std::string". Both of those are already done. The irritating thing is that the first class I made does not give me this error. Any subsequent class I made does however. I even copy & pasted this code into another IDE (NetBeans) and got the same error.

Here's the code for my first class so you can see.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//CompObj.h
#ifndef COMPOBJ_H
#define COMPOBJ_H

class CompObj
{
    public:
        CompObj();
        virtual ~CompObj();
        bool IsRunning();
        void Go(std::string);

    protected:
    private:
        bool isRunning;
        std::string object; //I threw this in here to test if having it under
                            //the 'private' category would make a difference.
};

#endif // COMPOBJ_H 


When trying to debug my AnEvent class, if I remove the std:: I get something to the effect of "'string' does not name a type". If I add "using namespace std;" I *still* get "'string' does not name a type". I cannot get my CompObj class to produce the same error.

If there's any more information you need, just ask.

Thanks in advance.
where is your #include <string> ?
Thank you, kind friend. That worked.

The reason it's not there is because...

1)My CompObj class doesn't have that and it still works. So I figured it was fine
2)I always thought <string> was necessary only when you wanted to do the fancy string functions associated with that class. At least, that's what I remember. I may be thinking of something else.

Anyway, if this is the solution, why does my CompObj class not need it?
You should include the headers that you use. string may be included via another header (such as iostream).
Topic archived. No new replies allowed.