3

I have the following code which compiles successfully in .

template<class T, class ...Args>
class B 
{
public:
   using AbcData = int;
};

template<typename ...Args>
class D : public B<float, Args...>
{
public:
   AbcData m_abc;
};

But when compiled in , it gives the following error.

error C2061: syntax error: identifier 'AbcData'

What is wrong with the code and how to fix this?

4
  • This shouldn't have compiled on C++14 either. Commented Jan 8, 2020 at 7:12
  • I'm using VisualStudio 2017. It compiles in c++14. Commented Jan 8, 2020 at 7:18
  • 2
    Shouldn't have. It's always been ill-formed. Demo. Commented Jan 8, 2020 at 8:01
  • 2
    It doesn't compile on MSVC with /Za, maybe they have an extension or something. Commented Jan 8, 2020 at 8:04

1 Answer 1

4

When the base class B class depends upon the template parameters, even though derived class D here type alias AbcData inherited from the B, using simply AbcData in D class, is not enough.

You need to be explicit, from where you have it

template<typename ...Args>
class D : public B<float, Args...>
{
public:
    typename B<float, Args...>::AbcData m_abc; // --> like this
};
Sign up to request clarification or add additional context in comments.

6 Comments

is this backward compatible with c++14 syntax?
@acegs Did you mean this: godbolt.org/z/qczVg7 ?
If AbcData is not ambiguous, you can use D itself instead of the base class B<float, Args...> to make the name dependent. That might be more straight-forward.
i'm using the AbcData multiple times so i used using AbcData = B<float, Args...>::AbcData. it's working now. is there better alternative that is shorter and less specifying too much redundant details? i also have other data types from base class not just AbcData.
@acegs Your line should not compile. It needs a typename before B and you can use using typename B<float, Args...>::AbcData; instead.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.