Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualbedtime

Posted 24 November 2012 - 10:59 AM

You might want to read this article: Organizing Code Files in C and C++. You have problem number two from that article.


Thank you so much for the quick response!

I read and found the answer. Excellent article. I found the issue and fixed it. Here is the advice for anyone that might want a quick glimpse at the answer:

quoted from article

There are more in-depth ways of resolving cyclic dependencies, but they are beyond the scope of this article. In 99% of cases, using forward declarations and favoring normal functions in C./.CPP files over inline functions in header files will be enough.


Working code:

[source lang="cpp"]#ifndef GAMEOBJECT_H#define GAMEOBJECT_H#include <iostream>#include <vector>#include <string>//#include "component.h"class Component;class GameObject{ std::vector<Component*> components; //A list of components attached to the game objectpublic: std::string name; //The unique name of the game object //Transform transform; //The object's transform //Initializing Ctor GameObject(std::string Name = "Default Player") : name(Name) { } ~GameObject() { } //Finds the attached component with the name Name (if it exists)/* Component* GetComponent(std::string Name) { } //Finds the attached component with the index Idx (if it exists) Component* GetComponentAt(int Idx) { }*/ //Attaches a component to the game object void AddComponent(Component* NewComponent) { components.push_back(NewComponent); } //Detaches the component with the name Name (if it exists) void RemoveComponent(std::string Name) { } //Detaches the component with the index Idx (if it exists) void RemoveComponentAt(int Idx) { } //Initializes the game object by initializing each of its attached components void Start() {} //Updates the game object by updating each of its attached components void Update() {}};#endif // GAMEOBJECT_H[/source]

#1bedtime

Posted 24 November 2012 - 10:57 AM

You might want to read this article: Organizing Code Files in C and C++. You have problem number two from that article.


Thank you so much for the quick response!

I read and found the answer. Excellent article. I found the issue and fixed it. Here is the advice for anyone that might want a quick glimpse at the answer:

quoted from article

There are more in-depth ways of resolving cyclic dependencies, but they are beyond the scope of this article. In 99% of cases, using forward declarations and favoring normal functions in C./.CPP files over inline functions in header files will be enough.


PARTNERS