By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,706 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

templating problem

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Rom" <no****@nono.com> wrote...
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
Jul 22 '05 #2

P: n/a
Rom

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:u8BPc.237339$XM6.128533@attbi_s53...
"Rom" <no****@nono.com> wrote...
I have a class difined as follows:


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
Jul 22 '05 #3

P: n/a
Rom posted:

"Victor Bazarov" <v.********@comAcast.net> wrote in message news:u8BPc.237339$XM6.128533@attbi_s53...
"Rom" <no****@nono.com> wrote...
> I have a class difined as follows:
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


The declaration is:

template<typename W> class testingW<W>;
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.