Reputation: 105
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>;
};
Upvotes: 1
Views: 80
Reputation: 76240
You'll have to use:
typename OrderManager<TOrderPolicy>::template item_t<int>
in place of:
item_t<int> test;
Upvotes: 2
Reputation: 105
wow, learning never stops. Until now I did not see the keyword template used in this context.
Upvotes: 0
Reputation: 65600
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;
Upvotes: 2