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
C++ templated class referencing each other [message #55096] Sun, 11 October 2020 00:45 Go to previous message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello,

I have 2 class :

Object.h
#include "ComponentManager.h"
class Object{
    public:
      Object() : componentManager(*this){}
     /*
         Many public things
     */
    private:
       ComponentManager componentManager;
};

ComponentManager.h

class Object;

class ComponentManager{
    public:
     ComponentManager(Object& _object) : object(_object){}

     template<class T> T& function1(...) 
     /*
        Many templated function that force me to write declaration in this .h file
     */
    private:
      Object& object;
}


My both class are made to work together, ComponentManager make no sens without an object etc...
All is fine and work well. Untill, in one of my templated function in ComponentManager, I need to use my Object reference to call a function of object :

template <class T> T& CreateComponent(bool active, int position){
/*
   Working code
*/
Object& obj = object.GetScene().GetObjectManager().GetObjects()[i];  //This line is problematic
/*
   Working code
*/
}

since I need to use some function of Object, compiler need Object declaration. But no way I can give to ComponentManager the implementation of object because Object need Compoment implementation. I can't split my CompomentManager into .h and .cpp so I'm kind of blocked.

Someone have an idea of how I could trick the compiler ? do I will need to change the way my architecture work (only for a function Sad).

here is the complete problematic chunck of code :
for(int i = 0; i <  object.GetScene().GetObjectManager().GetObjectsCount(); i++){
	Object& obj = object.GetScene().GetObjectManager().GetObjects()[i];
	if(&obj != &object){
		if(obj.GetComponentManager().HasComponent<T>()){
			throw Exc("...");
		}
	}
}


I have thinked about externalise in a .cpp a function (not templated) which do the job and then I could have include in the .cpp the Object defintion but since I need to call some Function with my templated class argument, I dont think I can work at all.

 
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 May 06 21:50:16 CEST 2024

Total time taken to generate the page: 0.02633 seconds