gpt4 book ai didi

c++ - this->... 在模板包装器类中需要

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:05:47 25 4
gpt4 key购买 nike

<分区>

请帮我解释一下为什么我不能在这种情况下直接调用 func1():

class A {
public:
void func1() {}
};

template <typename wrapped_type>
class B : public wrapped_type {
public:
void func2() {
func1();
}
};

B<A> b;

上述代码在调用 func1() 时导致“error C3861: 'func1': identifier not found”。但是如果我用以下两个选项之一替换这个调用,那么它可以编译成功:

this->func1();

wrapped_type::func1();

据我所知,模板类只有在确定所有类型参数时才真正编译。

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