3

Getting this error when compiling a basic class and header. Not sure if I'm missing something obvious? Can provide any additional details if needed.

Note: I added #include <string> in Event.h and the error remains.

Event.cpp

#include "Event.h"
#include <string>

std::string Event::getLabel() {
    return label;
}

Event.h

#ifndef EVENT_H
#define EVENT_H

#define EVENT_STOP 0
#define EVENT_START 1


class Event {
private:

protected:
    double time;
    std::string label;
    int type; // EVENT_START OR EVENT_STOP

public:
    std::string getLabel(); 

};

#endif

compile and error

g++ -c -Wall -pedantic correngine.cpp
g++ -c -Wall -pedantic CSVManager.cpp
g++ -c -Wall -pedantic ServerEvent.cpp 
g++    -c -o UPSEvent.o UPSEvent.cpp
g++ -c -Wall -pedantic CorrelationEngineManager.cpp
g++ -c -Wall -pedantic Event.cpp
Event.cpp:4: error: no ‘std::string Event::getLabel()’ member function declared in class ‘Event’
make: *** [Event.o] Error 1

2 Answers 2

10

I had a similar problem, and solved it by removing the [header name].gch file that had been generated next to the header, and which apparently had been corrupted. Maybe you can try that?

Sign up to request clarification or add additional context in comments.

2 Comments

+1: This is the first thing to check, and ends up working so often that it just isn't funny... (well, ok, so maybe it is a little bit funny)
Interesting. Is there a way to do this without manually deleting files? Like the clean or rebuild options in some IDE-s or compilers, which scrap every temporary or intermediate files and start over, exactly to solve this kind of problem.
4

You need to include std::string header in Event.h

#ifndef EVENT_H
#define EVENT_H

#include <string>        //<<----  here

#define EVENT_STOP 0
#define EVENT_START 1


class Event {
private:

protected:
    double time;
    std::string label;
    int type; // EVENT_START OR EVENT_STOP

public:
    std::string getLabel(); 

};

#endif

7 Comments

you include it at wrong place, include it in Event.h file not Event.cpp
I definitely included it in the header. I put it in both files, too.
That's interesting, I compiled your code with #include <string>, then the error message goes away in my environment. I don't see any reason it fails if you include necessary headers.
I changed the types to int and the same error is appearing (replacing int with std::string), so that wasn't the issue.
@user2089851: My guess would be that there is another unrelated Event class in scope that is confusing the compiler. Try changing the name of your class to something else. If the error persists, then something screwy is going on.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.