C++ - 默认参数不能添加到类模板成员的外联定义中

标签 c++ ios openframeworks

我有一个 iOS 应用程序,它使用 MPL 中名为“square.h”的 C++ 类,每当我构建该应用程序时,Xcode 都会抛出此错误 -

不能将默认参数添加到类模板成员的外联定义中

现在,我对C++语法的了解很少,那么这个错误是什么意思呢?

有问题的行在下面 -

template <class T> 
TSquare<T>::TSquare (T size_, T x_, T y_, T scale_=0)
{
    size = size_;
    x = x_;
    y = y_;
    scale = scale_;
}

最佳答案

默认参数不是定义的一部分,只是声明:

template <class T>
class TSquare
{
public:
    TSquare (T size_, T x_, T y_, T scale_ = 0);
};

// out-of-line definition of a member of a class template:
template <class T>
TSquare<T>::TSquare (T size_, T x_, T y_, T scale_ /* = 0 */)
{

}

或:

template <class T>
class TSquare
{
public:
    // in-line definition of a member of a class template
    TSquare (T size_, T x_, T y_, T scale_ = 0)
    {

    }
};

关于C++ - 默认参数不能添加到类模板成员的外联定义中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25647199/

相关文章:

c++ - 仅在 Eclipse 中不识别在一个位置的 ofstream 声明

c++ - 端口Audio和Libsndfile没有数据?

c++ - 服务器和客户端同时使用 Boost-Asio

ios - centralManager 方法未被调用

ios - Swift SQLite 如何从表中获取 row.count?

c++ - 具有大特征向量 LibSVM 的段错误

c++ - OpenFrameworks testApp 的 "Right Way"有 ofColor 成员?

c++ - 复制的可执行文件是否会在没有库的情况下在新机器上运行

ios - 在 UI 测试中执行完全向左滑动操作?

c++ - 按位运算符并将 int 转换为 2 个字节并再次返回