I have two class with a vector that holds instances of a third class.
Basically I have three classes:
Corporation and market can have 0..* equities and equities must be linked to 1 market and 1 corporation (to print values, etc...)
I don't know how to do that properly. For me the problem is when I do one vector of equities in market and coporation, I can't put a link in Equities for Corporation and Market because when the Equities.h is the first it don't know Market and Corporation class found in Equities class. And if Corporation.h and Market.h are the first it say me than it don't know the Equities class found in Corporation and Market class.
What is the best code to build the solution for this? I can't say to VisualStudio to go away when he see a class than it never see already? (because the definition is just to the next so it change nothing ... :( ) It's impossible in C++ to have in the first class : a link or a vectorof the second class and in the second class : a link or a vector of the first class without having a problem when we build the solution?
Edit:
It's work, I wrote "class Equities; class Corporation; class Market;" and it didn't care about the fact that it didn't know these classes. Thank to everyone it was so quick! I will read your link when I will finish my job. :)
The simplest way is to forward declare or prototype all the classes and types in a common header, place guards on that, and include the header from all your code files. For example:
header.hpp:
#ifndef COMMON_HPP
#define COMMON_HPP
class Corporation;
class Market;
class Equities;
typedef std::shared_ptr<Corporation> CorpRef;
typedef std::list<CorpRef> CorpList;
#endif /*COMMON_HPP*/
body.cpp:
#include header.hpp
class Corporation
{
static CorpRef Create();
};
and so on.
If you're using Visual Studio exclusively, you can use #pragma once
in place of the #ifndef
guards.