I\'m trying to get the following C++ code running:
#include
template class ConditionalData {
};
template
First of all, you don't require 3 versions of class ConditionalData
, because bool
can be either true
or false
. So let me simplify it as following:
template class ConditionalData {
}; //^^^^^^^^^^^^
template class ConditionalData {
private:
T data;
public:
void setData(T _data) { data = _data; }
};
Secondly, to answer your question: Whichever members are falling for false
category, just overload them outside the class
body as following:
template class A {
public:
A() {
ConditionalData data;
if (hasdata) {
data.setData(3);
}
}
};
template<> A::A() {} // Does nothing for `false` condition