Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > template template arguments: expected a class template, got `Component<T1, T2, T3>

Reply
Thread Tools

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

 
 
gary.bernstein@gmail.com
Guest
Posts: n/a
 
      06-08-2007
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();
}

 
Reply With Quote
 
 
 
 
Gianni Mariani
Guest
Posts: n/a
 
      06-08-2007
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();
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declaring a template class with two template params a friend in anon-template class A L C++ 1 08-25-2010 07:25 AM
MatchData captures... expected two items, but got one? Sarah Allen Ruby 7 03-02-2010 06:11 PM
error: expected class-name before "class" muthuselvan C++ 1 08-04-2009 09:14 AM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57