使用模板变量访问基类的结构
我想创建一个具有模板的基类的派生类并保留模板选项
,但我无法访问属于基类一部分的结构,
这是一个示例:
template <typename T1>
class Base{
public:
Base(){}
~Base(){}
struct Struct {
int Integer=0;
};
virtual void Function(Struct NewStrcut){ }
//void Proccess(int T_Var){
void Proccess(T1 T_Var){
// do something
}
};
template <typename T>
class Derived : public Base<T>{
//class Derived : public Base{
Derived(){}
~Derived(){}
void Function(Struct NewStrcut){
// do something
}
};
我收到以下错误:
错误:“结构”尚未声明 [build] 51 |空白 函数(结构NewStrcut){
我在 Ubuntu18 上使用 c++17 和 GCC11
I want to create a derived class of base class that has a template and to keep the template option
but I cannot access a struct that is part of the base class
here is an example:
template <typename T1>
class Base{
public:
Base(){}
~Base(){}
struct Struct {
int Integer=0;
};
virtual void Function(Struct NewStrcut){ }
//void Proccess(int T_Var){
void Proccess(T1 T_Var){
// do something
}
};
template <typename T>
class Derived : public Base<T>{
//class Derived : public Base{
Derived(){}
~Derived(){}
void Function(Struct NewStrcut){
// do something
}
};
I get the following error:
error: ‘Struct’ has not been declared [build] 51 | void
Function(Struct NewStrcut){
I am using c++17 with GCC11 on Ubuntu18
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
多亏了 @πάνταῥεῖ@fareanor,我发现一个答案
只需要添加“ TypeName base ::”在struct之前
,请在以下代码中看到:
thanks to @πάνταῥεῖ @Fareanor I found an answer
just needed to add "typename Base::" before Struct
as you can see in the following code: