gpt4 book ai didi

c++ - "primary-expression before ' 。 g++ 中的 ' token error"

转载 作者:太空狗 更新时间:2023-10-29 20:06:58 24 4
gpt4 key购买 nike

我有这个 C++ 代码来生成“'.' 之前的主表达式” g++ 编译器出现 token' 错误。使用 cl (MSVC) 编译器编译正常。

template<typename T>
class A : public std::auto_ptr<T>
{
typedef std::auto_ptr<T> Super;
public:
A() : Super() { }
A(T* t) : Super(t) { }
A(AP<T>& o) : Super(o) { }
operator bool() { return !!Super.get(); } <--- error!
};

这段代码有什么问题?

最佳答案

Super 是一种类型。如果你想调用基类函数,你可以通过this来实现:

this->get();

注意this->只是在这里需要,因为get()是依赖基类的成员函数;即,依赖于模板参数 T 的基类。有关详细信息,请参阅 Parashift C++ 常见问题解答文章,"Why am I getting errors when my template-derived-class uses a member it inherits from its template-base-class?"

关于c++ - "primary-expression before ' 。 g++ 中的 ' token error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5249747/

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