相关疑难解决方法(0)

使用const引用的Constexpr类未编译

我有以下示例代码

template<class T1, class T2>
class Operation
{
public:
    constexpr Operation(const T1& lhs, const T2& rhs) noexcept
        : m_lhs(lhs), m_rhs(rhs) { }

private:
    const T1& m_lhs;
    const T2& m_rhs;
};

int main()
{
    constexpr int a = 3;
    constexpr int b = 4;

    constexpr Operation op(a, b);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我用cygwin(gcc 8.2)编译

template<class T1, class T2>
class Operation
{
public:
    constexpr Operation(const T1& lhs, const T2& rhs) noexcept
        : m_lhs(lhs), m_rhs(rhs) { }

private:
    const T1& m_lhs;
    const T2& m_rhs; …
Run Code Online (Sandbox Code Playgroud)

c++ reference constexpr c++17

2
推荐指数
1
解决办法
81
查看次数

标签 统计

c++ ×1

c++17 ×1

constexpr ×1

reference ×1