I'm trying to write a program like so:
I have a cpp file I waould like to run and create objects of 2 classes.
Each class has a field of the other class.
I can't seem to solve this after a lot of trials and searches.
Can anyone help?
added the code:
/*
* Classes.cpp
*
* Created on: Nov 4, 2012
* Author: achie
*/
#include <iostream>
#include <string>
#include "../include/classes.h"
#include "../include/Class1.h"
#include "../include/Class2.h"
In file included from src/../include/Class1.h:13:0,
from src/Class1.cpp:8:
src/../include/../include/Class2.h:23:28: error: ‘Class1’ was not declared in this scope
src/../include/../include/Class2.h:23:34: error: template argument 1 is invalid
src/../include/../include/Class2.h:23:34: error: template argument 2 is invalid
src/../include/../include/Class2.h:26:9: error: ‘Class1’ was not declared in this scope
src/../include/../include/Class2.h:26:15: error: template argument 1 is invalid
src/../include/../include/Class2.h:26:15: error: template argument 2 is invalid
src/Class1.cpp: In constructor ‘Class1::Class1(int, std::vector<Class2>)’:
src/Class1.cpp:11:1: warning: ‘Class1::number’ should be initialized in the member initialization list
src/Class1.cpp:11:1: warning: ‘Class1::Class2Classes’ should be initialized in the member initialization list
Circular dependencies indicate a design flaw. If two classes require each other to be built, then a misunderstanding of what a class is supposed to do has occurred.