I'm having a weird behavior concerning a template method calling a template variadic method and I can't find what's the problem. I'm using Visual Studio Community 2017.
The compile error is appearing in the following method :
// AScene.hpp
#include "Scriptable.hpp"
template <typename T>
void AScene::initialize_(void) {
std::shared_ptr<AGameObject> root = std::make_shared<T>();
// ...
root->addComponent<Scriptable>(3); // it works (3 is just a random value to bypass the default constructor, see below the Scriptable struct definition)
root->addComponent<Scriptable>(); // error C2760 unexpected token ')', expected 'expression'
// ...
}
If I try to use the default constructor in this method, I have the compile error mentionned above. This method is called in a derived class, here :
// MyScene.cpp
#include "AScene.hpp"
void MyScene::initialize(void) {
AScene::initialize_<Level>();
// If I call root->addComponent<Scriptable>() directly here, its working perfectly
}
Here is the implementation of the addComponent template variadic method :
// AGameObject.hpp
template <typename C, typename ...Args>
void AGameObject::addComponent(Args&& ... args) {
entity_.assign<C>(std::forward<Args>(args) ...);
}
I can't show you the assign() code since it's part of a library, but this code is always working when I don't call it in the initialize_.
And here is my Scriptable class :
// Scriptable.hpp
struct Scriptable {
Scriptable(void) = default;
Scriptable(int i) {} // remember, used to bypass the default constructor
// ...
};
In fact, it seems that the compiler just ignore/can't find the default constructor when I'm calling the addComponent method in the template method initialize_. Do you know what I'm doing wrong ?
If you need further information, please tell me.
EDIT :
I just checked the assign() implementation in the library and the constructor is called like that :
C(std::forward<Args>(args) ...);
Here is the link if you want to check it : https://github.com/alecthomas/entityx/blob/master/entityx/Entity.h#L648
Here is exactly what the compiler tell me :
1>AGameObject.cpp
1>path\ascene.hpp(89): error C2760: syntax error: unexpected token ')', expected 'expression'
1>path\ascene.hpp(89): note: This diagnostic occurred in the compiler generated function 'void AScene::initialize_(void)'