I'm working on a project using Qt Creator.
Let's say I have a simple Tool class:
#ifndef TOOL_H
#define TOOL_H
#include <map>
#include <string>
#include "myobject.h"
class Tool
{
public:
Tool();
private:
const std::map<std::string, MyObject*> myMap;
};
#endif // TOOL_H
with a default constructor like this:
#include "tool.h"
using namespace std;
Tool::Tool()
{
myMap = new map<string, MyObject*>();
// populate myMap
}
Then I want to use the class in the constructor of another class:
#include "myclass.h"
using namespace std;
MyClass::MyClass()
{
Tool t;
}
But I get the following compile error:
In function 'MyClass::MyClass()':
undefined reference to 'Tool::Tool()'
Naturally, myclass.h includes tool.h, so I don't understand why it can't find it. I tried using a pointer, declaring t as a member variable, but I keep getting this error.
I tried to make a minimal project outside mine using these classes and compiled it with g++ (Tool and then MyClass with a main function); it worked. So maybe it's a problem with how Qt Creator handles compile and linking? But I don't know which option to check.
Thank you for any ideas.
EDIT: The problem came from the Qt Creator environment. I actually created MyClass before Tool, and without cleaning the project compile failed without telling me what the error was; the true error was myMap = new map<string, MyObject*>();
in the Tool class, so Tool was never compiled (as Jarod42 mentioned), thus the compile error for MyClass.
Cleaning and rebuilding pointed out that true error and allowed me to fix my project.