Reputation: 995
I'm using Embarcadero RAD Studio XE C++ Builder. I'm having a little problem getting my STL map to work correctly.
#ifndef BbTabManagerH
#define BbTabManagerH
#include "BbSeExplorer.h"
#include "BbTabPage.h"
#include <map>
#define TAB_MANAGER_MAX_TABS 7
class TBbSeExplore;
typedef std::map<std::string, BbTabPage> TabPageMap;
typedef std::map<std::string, BbTabPage>::iterator TabPageMapIt;
My problem is on the following line:
typedef std::map<std::string, BbTabPage> TabPageMap;
This gives me a compiler error:
[BCC32 Error] BbTabManager.h(13): E2451 Undefined symbol 'BbTabPage' Full parser context stdafx.h(229): #include ..\src***\Gui\Utilities\BbTabPage.h BbTabPage.h(5): #include ..\src***\Gui\Frames\BbSeExplorer.h BbSeExplorer.h(10): #include ..\src****\Gui\Utilities\BbTabManager.h
I find this weird, I included 'BbTabPage.h', which declares the class 'BbTabPage', so where does the undefined symbol come from?
I tried doing a forward declaration like this:
class BbTabPage;
But that doesn't seem to make much of a difference, except that it gives me a whole lot more compiler errors. The strange thing is that if I change it to a pointer:
typedef std::map<std::string, BbTabPage*> TabPageMap;
Everything compiles just fine.
This problem is driving me nuts, I've been trying to find a solution for hours. Are there some kind of requirements a class must comply with to be used as a value in a map?
Upvotes: 1
Views: 1153
Reputation: 87959
Look like a problem with circular includes
BbTabPage.h includes BbSeExplorer.h
BbSeExplorer.h includes BbTabManager.h
BbTabManager.h includes BbTabPage.h
So the first time you hit your typedef BbTabPage
has not been defined because the include guard from the partly processed BbTabPage.h prevents BbTabManager.h from including BbTabPage.h.
The answer is to reorganize your headers so they don't have a circular include. If two classes are completely dependent on each other then it's best to put them both in the same header file, so you can control more carefully what gets seen in what order.
Upvotes: 3