Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » C++ templated class referencing each other
Re: C++ templated class referencing each other [message #55107 is a reply to message #55096] Sun, 11 October 2020 16:38 Go to previous messageGo to previous message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello Lance,

Thanks for the time you take.

CompManagerEx.h


Did not worked for me. I had compilation error saying it was impossible to define/redefine CreateComponent because it was out of Upp (even if it was in Upp namespace)

Quote:
Notice that I essentially put everything in the same header file (equivalently).

It dont work either, it fix the circulare dependencies between my problematic code and Object definition, however it also need the Scene object definition. If I include this definition in object.h file (since ComponentManager is in object.h file) it will lead to the same problem, circular dependencies include (because Scene include ObjectManager which include Object which will include Scene...)


Quote:
Also, if your can guarantee that ComponentManager Will be the first member variable (because why-not and you should put a static_assert to avoid accidently add some other member variable in front it subsequently), you can probably save the
Object& obj;

member variable in the ComponentManager class. Simply define it like:
class Object;

class ComponentManager{
public:
ComponentManager(){}

template <class T> T& CreateComponent(bool active, int position);

/*
Many templated function that force me to write declaration in this .h file
*/
private:
Object& object(){
return *reinterpret_cast<Object*>(this);
}

};


And change other part of your code accordingly.


I dont really understand this solution, are you meaning inherriting privatly/publicly Object from componentManager ? if yes I'm afraid the problem will remain since circulare reference between Scene and Object.h will appear. Maybe my architecture is bad and should be change to something like Opaque pointer
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: operation involving "\\" x "\" characters in directories and files
Next Topic: Shrila Prabhupada Sanskrit Slovary
Goto Forum:
  


Current Time: Sun Aug 24 19:23:53 CEST 2025

Total time taken to generate the page: 0.05610 seconds