Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

An issue with alias

22 views
Skip to first unread message

Daniel

unread,
Dec 7, 2016, 4:52:53 PM12/7/16
to
Code below compiled with vs2015:

#include <vector>

struct SomeTraits
{
template <class T>
using vec = std::vector<T, std::allocator<T>>;
};

template <class Traits>
struct A
{

typedef typename Traits::vec<int> v1_t; // (1)

using v2_t = typename Traits::vec<int>; // (2)
};

int main()
{
typedef SomeTraits::vec<int> v_t1;
using v_t2 = SomeTraits::vec<int>;

v_t1 v1; // OK
v_t2 v2; // OK

A<SomeTraits> a; // Not OK
}

Instantiating A<SomeTraits> results in "syntax error: '<'" for both (1) and (2).
Is that expected?

Thanks,
Daniel

Alf P. Steinbach

unread,
Dec 7, 2016, 7:00:57 PM12/7/16
to
Yes.

You have to tell the compiler about dependent names when they're types
(you've done that, added `typename`) and when they're templates (need to
add `template`):

template <class Traits>
struct A
{
typedef typename Traits::template vec<int> v1_t; // (1)
using v2_t = typename Traits::template vec<int>; // (2)
};

Cheers & hth.,

- Alf

Daniel

unread,
Dec 7, 2016, 9:41:33 PM12/7/16
to
On Wednesday, December 7, 2016 at 7:00:57 PM UTC-5, Alf P. Steinbach wrote:
> You have to tell the compiler about dependent names when they're types
> (you've done that, added `typename`) and when they're templates (need to
> add `template`):

Thanks!
Daniel
0 new messages