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

标签 c++ g++

我有这个 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/

相关文章:

c++ - 以编程方式获取 powershell.exe 的完整路径

c++ - 具有非默认构造函数且不使用 STL 的对象数组

c++ - 使用 g++ 编译多个 .cpp 和 .h 文件。我做对了吗?

c++ - 如果容器没有其实例,则访问嵌套类

c++ - Anttweakbar glfw3 OpenGL 3.2 不绘图

c++ - 为什么我不需要 std::move 到 std::bind 函数?

c++ - 从 constexpr 函数返回一个类需要使用 g++ 的 virtual 关键字

c++ - 无法编译 Crow 示例 - boost/optional.hpp : No such file or directory

c++ - 如何在 linux 平台上使用 openGL glDebugOutput/glDebugMessageCallback

c++ - 为 ubuntu 写一个 cygwin makefile