问题
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