# Subclasses of C++ template classes

**URL:** <https://boards.straightdope.com/t/subclasses-of-c-template-classes/390751>\
**Category:** Factual Questions\
**Created:** [February 4, 2007, 5:23am UTC](https://boards.straightdope.com/t/subclasses-of-c-template-classes/390751 "2007-02-04T05:23:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Orbifold](https://avatars.discourse-cdn.com/v4/letter/o/779978/32.png) [@Orbifold](https://boards.straightdope.com/u/Orbifold)\
**Post date:** [February 4, 2007, 5:23am UTC](https://boards.straightdope.com/t/subclasses-of-c-template-classes/390751/1 "2007-02-04T05:23:58Z")

</div>

My C++ skills are a little rusty, specifically concerning templates, and for the life of me I can’t figure out what the problem is with the following code snippet (abstracted from a larger program, obviously):

```auto

template<class T> struct Bar
{
  struct Baz { };
};

template<class T> void Foo()
{
  Bar<int>::Baz baz_int;
  Bar<T>::Baz baz_t;
};

```

When I try to compile the above code (under g++ 3.4.6 on a Linux box) it chokes on the declaration of baz\_t. Specifically, I get

```auto

error: expected `;' before "baz_t"

```

Which suggests that the code isn’t parsing properly, but then why doesn’t the compiler have any problems with the declaration of “baz\_int”?

I’m trying to create a template class that uses the STL classes as members, but if I can’t figure this problem out that will be rather difficult: replace “Bar” with “std::list” and “Baz” with “iterator” and you’ll see why I want to know what the heck I’m doing wrong.

Help, please! Does anybody know what the problem is?

---

<div class="post-metadata">

**Author:** ![Orbifold](https://avatars.discourse-cdn.com/v4/letter/o/779978/32.png) [@Orbifold](https://boards.straightdope.com/u/Orbifold)\
**Post date:** [February 4, 2007, 6:38am UTC](https://boards.straightdope.com/t/subclasses-of-c-template-classes/390751/2 "2007-02-04T06:38:32Z")

</div>

So, naturally, it’s only _after_ I post the thread that my Google-fu comes through and I finally find the answer for myself. (For the record, the correct declaration is “ **typename** Bar\<T\>::Baz baz\_t”.)

:smacks self in forehead:

Off to e-mail a mod…
