オプションの型パラメーターを持つクラスを作成したい場合は、次のようにすることができます。
template<typename T>
struct X
{
T t;
};
template<>
struct X<void>
{
};
int main()
{
X<int> a;
X<void> b;
};
ボイドが不要になるように書く方法はありますか?すなわち:
int main()
{
X<int> a;
X b;
};
私はこれを試しました:
template<typename T = void>
struct X
{
T t;
};
template<>
struct X<void>
{
};
int main()
{
X<int> a;
X b;
};
しかし、私は得る:
test.cpp: In function ‘int main()’:
test.cpp:16:4: error: missing template arguments before ‘b’
test.cpp:16:4: error: expected ‘;’ before ‘b’