templating problem

R

Rom

I have a class difined as follows:

template <typename W>

class testingW {

public:
.........
private:
W testW;
}


Now I have another class

class testingW; //make the testingW class visible

template <typename T>
class testingT{

public:

vector < testingW<T> > getTestingW() const; // <------- Error Here

private:

T testT;

}


In short, I'm trying to return a vector that contains a series of
testingW<T> objects however my compiler says it is an illegal template
argument (using CodeWarrior as my compiler), what am I missing here?

If I simply try vector < testingW > getTestingW() const; then
it says it is expecting "<" , I'm assuming it wants <T> where T can be
anything but as I said it produces an error

Any help would be much appreciated
 
V

Victor Bazarov

Rom said:
I have a class difined as follows:

No, it's not a class. It's a template.
template <typename W>

class testingW {

public:
........
private:
W testW;
} ;



Now I have another class

class testingW; //make the testingW class visible

That's an error. 'testingW' is not a class, it's a template.
template <typename T>
class testingT{

public:

vector < testingW<T> > getTestingW() const; // <------- Error Here

Of course it is. You just told the compiler that 'testingW' is a class,
not a template. Now you're trying to give it a template argument list
as if it were a template. That's why the compiler complains.
private:

T testT;

} ;



In short, I'm trying to return a vector that contains a series of
testingW<T> objects however my compiler says it is an illegal template
argument (using CodeWarrior as my compiler), what am I missing here?

You're missing the fact that classes and templates are not the same thing.
If I simply try vector < testingW > getTestingW() const; then
it says it is expecting "<" , I'm assuming it wants <T> where T can be
anything but as I said it produces an error

Any help would be much appreciated


Define the 'testingW' template before 'testingT', then everything is going
to be fine, no need in forward-declaration. If you think you do need the
forward-declaration, do it right:

template<class T> class testingW;

BTW, did you include <vector>? Did you say "using std::vector;"? If you
didn't, you need to qualify the 'vector' name:

std::vector<testingW<T> > getTestingW() const;

V
 
R

Rom

Victor Bazarov said:
No, it's not a class. It's a template.

Yes, I've been seeing the template as a generalized class (now everything
makes sense)

Thanks again for your help
 
J

JKop

Rom posted:
Yes, I've been seeing the template as a generalized class (now everything
makes sense)

Thanks again for your help

The declaration is:

template<typename W> class testingW<W>;
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,173
Messages
2,570,938
Members
47,481
Latest member
ElviraDoug

Latest Threads

Top