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 #55100 is a reply to message #55096] Sun, 11 October 2020 04:36 Go to previous messageGo to previous message
Lance is currently offline  Lance
Messages: 656
Registered: March 2007
Contributor
Notice that I essentially put everything in the same header file (equivalently).

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.


PS: If your Object class is virtual, some compiler might put vtable at this. In this case, above hack will be problematic. I will consider to let Object to privately inherit from ComponentManager.

[Updated on: Sun, 11 October 2020 04:45]

Report message to a moderator

 
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: Mon Aug 25 00:48:54 CEST 2025

Total time taken to generate the page: 0.05286 seconds