template template arguments: expected a class template, got `Component<T1, T2, T3>

Discussion in 'C++' started by gary.bernstein@gmail.com, Jun 8, 2007.

  1. Guest

    Any idea why line 57 fails? http://rafb.net/p/86JdGg61.html

    gs = MyShutdown<Component, T1, T2, T3>(this);

    Errors:

    shutdown1.cpp: In constructor `Component<T1, T2, T3>::Component(int)':
    shutdown1.cpp:46: error: type/value mismatch at argument 1 in template
    parameter list for `template<template<class T1, class T2, class T3>
    class Calling_Comp
    onent, class T1, class T2, class T3> class MyShutdown'
    shutdown1.cpp:46: error: expected a class template, got
    `Component<T1, T2, T3>'

    #include <iostream>
    #include <string>

    using namespace std;


    class Shutdown
    {
    virtual void begin()
    {
    cout << "shutdown" << endl;
    exit(0);
    }
    };

    Shutdown *gs;

    template <template <class T1, class T2, class T3> class
    Calling_Component, class T1, class T2, class T3>
    class MyShutdown : public Shutdown
    {
    typedef Calling_Component<T1, T2, T3> Caller;

    Caller& mCaller;

    public:
    MyShutdown(Caller& rCaller)
    : mCaller(rCaller)
    {
    }

    void begin()
    {
    cout << "MyShutdown caller # " << mCaller.mnId << endl;
    exit(0);
    }
    };

    template <typename T1, typename T2, typename T3>
    class Component
    {
    public:

    Component(int n)
    : mnId(n)
    {
    gs = MyShutdown<Component, T1, T2, T3>(this);
    }

    int mnId;
    };

    int main()
    {
    Component<int, int, string> c(5);

    MyShutdown<Component, int, int, string> s(c);

    s.begin();
    }
     
    , Jun 8, 2007
    #1
    1. Advertising

  2. Re: template template arguments: expected a class template, got `Component<T1,T2, T3>

    wrote:
    > Any idea why line 57 fails? http://rafb.net/p/86JdGg61.html

    ....
    > MyShutdown(Caller& rCaller)


    do you mean to be passing a reference or a pointer ?

    > : mCaller(rCaller)
    > {
    > }
    >
    > void begin()
    > {
    > cout << "MyShutdown caller # " << mCaller.mnId << endl;
    > exit(0);
    > }
    > };
    >
    > template <typename T1, typename T2, typename T3>
    > class Component
    > {
    > public:
    >
    > Component(int n)
    > : mnId(n)
    > {
    > gs = MyShutdown<Component, T1, T2, T3>(this);


    Even though Component is an appropriate template, the compiler (rightly
    or wrongly (i'm not sure) is interpreting Component as the specialized
    type in this context. BTW - this is a pointer no a reference.

    ....


    Here is code that compiles - not sure if it does what you want. Note
    that <: has special meaning in C++ (look up digraph) so make sure you
    leave a space between < and ::.

    #include <iostream>
    #include <string>

    using namespace std;

    class Shutdown
    {
    virtual void begin()
    {
    cout << "shutdown" << endl;
    exit(0);
    }
    };

    Shutdown *gs;

    template <template <class, class, class> class
    Calling_Component, class T1, class T2, class T3>
    class MyShutdown : public Shutdown
    {
    typedef Calling_Component<T1, T2, T3> Caller;

    Caller& mCaller;

    public:
    MyShutdown(Caller& rCaller)
    : mCaller(rCaller)
    {
    }

    void begin()
    {
    cout << "MyShutdown caller # " << mCaller.mnId << endl;
    exit(0);
    }
    };

    template <typename T1, typename T2, typename T3>
    class Component
    {
    public:

    Component(int n)
    : mnId(n)
    {
    gs = new MyShutdown</* space */::Component, T1, T2, T3>(*this);
    }

    int mnId;
    };


    //} //namespace XX

    int main()
    {
    Component<int, int, string> c(5);

    MyShutdown< Component, int, int, string> s(c);

    s.begin();
    }
     
    Gianni Mariani, Jun 8, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. christopher diggins
    Replies:
    16
    Views:
    756
    Pete Becker
    May 4, 2005
  2. shawn a

    TypeError: no arguments expected

    shawn a, Dec 12, 2005, in forum: Python
    Replies:
    6
    Views:
    318
    shawn a
    Dec 12, 2005
  3. muthuselvan

    error: expected class-name before "class"

    muthuselvan, Aug 4, 2009, in forum: C Programming
    Replies:
    1
    Views:
    1,008
    muthuselvan
    Aug 4, 2009
  4. Pedro Del Gallego

    blocks expected arguments and metaprogramming

    Pedro Del Gallego, Sep 16, 2007, in forum: Ruby
    Replies:
    4
    Views:
    101
    Pedro Del Gallego
    Sep 16, 2007
  5. Sarah Allen
    Replies:
    7
    Views:
    163
    Roger Pack
    Mar 2, 2010
Loading...

Share This Page