Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualThe King2

Posted 13 March 2013 - 11:12 AM

YAML-cpp is sample code for how it is achieved, that's why I linked to it. You don't need to use a library to learn from it.

 

Oh, my bad. Reading about JSON files in EWClays post actually before reading yours confused me from the real purpose of your link... I'll definitaley check it out, along with the variadic templates and decide which fits my need better afterwards

 

 

About MSVC2012 - it supports variadic templates and few more C++11 features when you install CTP_Nov2012 (http://www.microsoft.com/en-us/download/details.aspx?id=35515) toolset and set it in your project options. Its CTP so its for testing but I use it and it works without problems. IMO having variadic templates is worth it smile.png

 

Ah, that worked, thanks... so I've tried to implement it, but don't know how to go any further.

 

template<typename... args>
class Arguments {};

class Component
{
public:
    template<typename... Args>
    virtual void StartUp(Arguments<Args...>) = 0; //???
    virtual void Update(void) = 0;
    virtual void HandleMessage(const Message& message) = 0;
};
 

So what I tried to make as an "Argument" class the takes how much arguments are needed, which would then get passed to the StartUp()-Function (if in the Entity or somewhere else shouldn't matter for now...). Only problem is that I get this error:

 

1>t:\dark mountain engine\repo\editor\component.h(13): error C2898: 'void Component::StartUp(Arguments<args...>)' : member function templates cannot be virtual (Component.cpp)

 

Obviously I can't do what I wanted to achieve here (have a function that takes a variadic template and by overloading that function each component will then decide how to use the argumentes. Is there just some syntax thing I didn't do, or is this whole approach faulty? If so, could you give me a short code example of how I'd achieve that? (variadic) templates are fairly new to me, and most examples I found in the internet are (seem to be) dealing with complete different things than what I want to achieve here, or I probably just don't understand it well enough...

 

Thanks in advance!

 

Edit:

Does entity really need to know how to construct components (and itself?) or it should be responsibility of class above entity, that picks needed components (probably out of templates later, so its more automated) and creates another instance of entity by attaching necessary components.

 

Well the Entity wouldn't really construct the component. It would just request an component object and pass its "StartUp()"-function the parameters specified, and the component itself takes care of its construction.


#1The King2

Posted 13 March 2013 - 10:36 AM

YAML-cpp is sample code for how it is achieved, that's why I linked to it. You don't need to use a library to learn from it.

 

Oh, my bad. Reading about JSON files in EWClays post actually before reading yours confused me from the real purpose of your link... I'll definitaley check it out, along with the variadic templates and decide which fits my need better afterwards

 

About MSVC2012 - it supports variadic templates and few more C++11 features when you install CTP_Nov2012 (http://www.microsoft.com/en-us/download/details.aspx?id=35515) toolset and set it in your project options. Its CTP so its for testing but I use it and it works without problems. IMO having variadic templates is worth it smile.png

 

Ah, that worked, thanks... so I've tried to implement it, but don't know how to go any further.

 

template<typename... args>
class Arguments {};

class Component
{
public:
    template<typename... Args>
    virtual void StartUp(Arguments<Args...>) = 0; //???
    virtual void Update(void) = 0;
    virtual void HandleMessage(const Message& message) = 0;
};
 

So what I tried to make as an "Argument" class the takes how much arguments are needed, which would then get passed to the StartUp()-Function (if in the Entity or somewhere else shouldn't matter for now...). Only problem is that I get this error:

 

1>t:\dark mountain engine\repo\editor\component.h(13): error C2898: 'void Component::StartUp(Arguments<args...>)' : member function templates cannot be virtual (Component.cpp)

 

Obviously I can't do what I wanted to achieve here (have a function that takes a variadic template and by overloading that function each component will then decide how to use the argumentes. Is there just some syntax thing I didn't do, or is this whole approach faulty? If so, could you give me a short code example of how I'd achieve that? (variadic) templates are fairly new to me, and most examples I found in the internet are (seem to be) dealing with complete different things than what I want to achieve here, or I probably just don't understand it well enough...

 

Thanks in advance!


PARTNERS