1

The following code gives the error (in line where i define test):

error C2143: syntax error: missing ';' before '<' note: see reference to class template instantiation 'ptc::Produce' being compiled error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Does anybody know why this happens? Compiler is VC2015 CTP1.

Edit: the error must happen in phase1 of the template parsing, because it occurs even I never instantiate the class Produce.

namespace OrderPolicy
{
    struct Unordered {};
    struct Ordered {};
};

template <typename TOrderPolicy>
struct OrderManager {};

template<>
struct OrderManager<OrderPolicy::Unordered>
{
    template <typename TItem>
    using item_t = TItem;
};

template<>
struct OrderManager<OrderPolicy::Ordered> 
{
    template <typename TItem>
    using item_t = TItem*;
};

template<typename TOrderPolicy>
struct Produce : public OrderManager<TOrderPolicy>
{
    item_t<int> test;
    //using item_type = item_t<int>;
};

Edit2: it works when I change the last part of the code to

struct Produce : public OrderManager<OrderPolicy::Ordered>
{
    item_t<int> test;
    //using item_type = item_t<int>;
};
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
bodzcount
  • 95
  • 1
  • 8

3 Answers3

2

You'll have to use:

typename OrderManager<TOrderPolicy>::template item_t<int>

in place of:

item_t<int> test;
Shoe
  • 74,840
  • 36
  • 166
  • 272
  • 1
    *"Type aliases are not imported from the base class"*, why? I think the problem is that the base class is a dependent one, so the name is not looked up there – Piotr Skotnicki Oct 26 '15 at 11:47
  • Yes, I checked it. Aliases are indeed imported, it just needs to know that its a template. – bodzcount Oct 26 '15 at 13:39
2
item_t<int> test;

That names a dependent template type from a base class. In this case, you need to tell the compiler both that item_t is a type in your base class, and that it's a template.

The direct way to do this is using typename and template:

typename OrderManager<TOrderPolicy>::template item_t<int> test;

As you can see, this will quickly become unreadable. I would make some local aliases to make the code neater:

using Base = OrderManager<TOrderPolicy>;
using item_type = typename Base::template item_t<int>;
item_type test;
Community
  • 1
  • 1
TartanLlama
  • 63,752
  • 13
  • 157
  • 193
0

wow, learning never stops. Until now I did not see the keyword template used in this context.

bodzcount
  • 95
  • 1
  • 8