Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4625488
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:16:47+00:00 2026-05-22T03:16:47+00:00

I don’t understand why this doesn’t compile: struct A {}; template<class T> struct B

  • 0

I don’t understand why this doesn’t compile:

struct  A
{};  

template<class T> 
struct  B
{};  

template<template<class> class T1, class T2> 
struct C
{};

int
main  (int ac, char **av)
{
  typedef B<double> b;              //compiles
  typedef B<const double> b_const;  //compiles
  typedef B<A> ba;                  //compiles
  typedef B<const A> ba_const;      //compiles

  typedef C<B,double> c1;           //compiles
  typedef C<B,const double> c2;     //compiles
  typedef C<const B,double> c3;     //ISO C++ forbids declaration of ‘type name’ with no type
}

(I find the reference to the standard a little cryptic)

What do I have to change to make it compile?

EDIT:

Compiler details (it seems to be relevent):

Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.4-14ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5) 

EDIT2:

By means of explaination, I am trying to do something like this:

template<template<class> class TheContainer, class T> 
struct Iterator

template<class T> 
struct  Container

typedef Iterator<Container, double> iterator;
typedef Iterator<const Container, double> const_iterator;

The technique for non-templated containers is found at the end of this boost doc: http://www.boost.org/doc/libs/1_46_1/libs/iterator/doc/iterator_facade.html

I guess the solution is not to nestle the templates. In retrospect it seems obvious.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:16:47+00:00Added an answer on May 22, 2026 at 3:16 am

    The first argument to C isn’t a type, hence it makes no sense to pass in a const-type as its arg. A template can’t be const or non-const, only types can be const or non-const. What does const B even mean?

    const int makes sense. const vector<int> makes sense, as does vector<const int>. But what would const vector mean?

    (Pinch-of-salt warning: I wasn’t even aware of template-template-classes before seeing this question.)

    To make this more concrete, imagine B and C are:

    template<class T>
    struct  B
    {
            T t;
    };      
    
    template<template<class> class T1, class T2>
    struct C
    {
            T2 t2;
            T1<T2> t1;
    };
    

    c2 will be of type

    C<B,const double>   
    ==>   struct { const double t2; T1<const double> t1;}
    ==> struct { const double t2; struct { const double b; } t1;}
    

    What would you expect c3 to be? That t1 would itself be const, while t1.b is non-const? I suppose that makes sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't understand where the extra bits are coming from in this article about
Don't you hate it when you have class Foobar { public: Something& getSomething(int index)
I don’t think I’ve grokked currying yet. I understand what it does, and how
I don't expect a straightforward silver bullet answer to this, but what are the
I don't know if anyone has seen this issue before but I'm just stumped.
Don't need to do this right now but thinking about the future... What would
Don't want to sort the entries. using this does not preserve the order as
I don't know if this is possible. I display a table of results and
I don't know if i am doing it right, this is what I got:
I don't think this should be in my view, but instead handled by the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.