const references in c++ templates

后端 未结 3 1243
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 09:53

In a C++ template with the generic type T, I can use

const T &

to get a reference to a constant T. However, if now T itself is a reference

3条回答
  •  面向向阳花
    2021-02-05 09:55

    Remove the reference:

    template
    void Test(const typename std::remove_reference::type & param)
    {
            param = 20;
    }
    

    Now it works as expected.

提交回复
热议问题