gpt4 book ai didi

c++ - 如何调节类模板和原始类型模板

转载 作者:行者123 更新时间:2023-11-30 02:21:47 25 4
gpt4 key购买 nike

<分区>

我正在尝试构建一个继承该类的类模板。如果类模板被赋予原始类型作为模板参数,那么它会给出非法继承错误。我试过做

template <class Class_>
struct EndianGuard_ : public Class_ {
EndianGuard_ () {
cout << "Guarding a Class" << endl;
}
}

template <typename PrimitiveType_>
struct EndianGuard_ {
EndianGuard_ (PrimitiveType_ Value) : Value(Value) {
cout << "Guarding a primitive type" << endl;
}
PrimitiveType_ Value;
}

当然我知道这样不行,但我很绝望。如何区分原始类型和结构?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com