“Can't resolve constructor” when using type alias inside class

a 夏天 提交于 2019-12-24 09:57:20

问题


I'm fairly new to C++, so please forgive me if I'm being naive here. I have a snippet that demonstrates my issue:

template<typename _T, typename _Key, typename _Val>
class Foo {
    typedef std::pair<_Key, _Val> _P1;
    using _P2 = std::pair<_Key, _Val>;

    _T *t = new _T();
    _P1 *p1 = new _P1();
    _P2 *p2 = new _P2(); // (IDE) error: can't resolve constructor '_P2'
}

My understanding is that using is equivalent to typedef. Why do the first two declarations work but the third one is flagged by my IDE? Furthermore, it compiles without errors and I can obtain _P2* pointers just fine. What's going on here?


回答1:


That's definitely a bug in CLion



来源:https://stackoverflow.com/questions/40564746/cant-resolve-constructor-when-using-type-alias-inside-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!