Why can't I use alias from a base class in a derived class with templates?

后端 未结 3 1870
Happy的楠姐
Happy的楠姐 2021-01-20 23:37

Consider this C++ code :

template
class Step
{
public:
   using Session_ptr = boost::shared_ptr;
protected:
   Session_pt         


        
3条回答
  •  广开言路
    2021-01-21 00:16

    This is because in StartSession class your Session_ptr type is seen as non dependent name, so it is being looked up with out instatiation of base class which is dependent. This is why you need to make reference to this name dependent some how, for example by qualifying it in a way as g++ suggests in warnings:

    note: (perhaps 'typename Step >::Session_ptr' was intended)
    

    btw. some compilers like Visual Studio (I checked it with 2015 now) will happily compile your code. This is because VS does not implement properly a two-phase template instantiation. See here for more on that: What exactly is "broken" with Microsoft Visual C++'s two-phase template instantiation?

提交回复
热议问题