Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

The C modest god

Template problem

This topic is 5325 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have the following code: template (class DATA) // Different parentheses because otherwise it dissapears class DataListLink { public: DataListLink (int Index, const DATA & Data, class DataListLink * pNext); DATA Data; int Index; class DataListLink * pNext; private: }; DataListLink(class DATA)/*other parentheses*/ ::DataListLink (int Index, const DATA & Data, class DataListLink * pNext) { } I get the following errors: d:\projects\targil\ex4\temp.h(9) : error C2079: 'Data' uses undefined class 'DATA' d:\projects\targil\ex4\temp.h(15) : see reference to class template instantiation 'DataListLink' being compiled Why I get those errors? [edited by - The C modest god on January 15, 2004 3:34:15 PM] [edited by - The C modest god on January 15, 2004 3:35:19 PM]

Share this post


Link to post
Share on other sites
Advertisement
If you declare it outside the class body, you need to repeat template<class DATA> in front of your constructor.

template<class DATA>
DataListLink<class DATA>::DataListLink (int Index, const DATA & Data, class DataListLink<DATA> * pNext)
{

}



“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan (C programming language co-inventor)


[edited by - Fruny on January 15, 2004 3:40:12 PM]

Share this post


Link to post
Share on other sites
The [source][/source] tags are helpful when posting template code. Or learn how to use &lt; and &gt;.

Share this post


Link to post
Share on other sites


// Make sure you have this include

#include <MyFooBar.h>

int DoSomething()
{
DataListLink <MyFooBar> list;

// yada yada

};




-----------
VenDrake

"My stupid jar is full. I can''t talk to you anymore."

Share this post


Link to post
Share on other sites
I get the same error for doing this code:


template <class DATA>
class DataListLink {
public:
DataListLink (int Index, const DATA & Data);

DATA Data;
int Index;
class DataListLink * pNext
private:
};

DataListLink <class DATA>::DataListLink (int Index, const DATA & Data)
{

}




[edited by - The C modest god on January 15, 2004 4:13:53 PM]

[edited by - The C modest god on January 15, 2004 4:14:41 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by SiCrane

template <class DATA>
DataListLink<DATA>::DataListLink (int Index, const DATA & Data)
{

}



That fixed the error, but now I have 3 new errors:

d:\projects\targil\ex4\temp.h(16) : error C2371: ''DATA'' : redefinition; different basic types
d:\projects\targil\ex4\temp.h(16) : error C2039: ''__ctor'' : is not a member of ''DataListLink''
d:\projects\targil\ex4\temp.h(16) : error C2935: ''DataListLink'' : template-class-id redefined as a global function

Share this post


Link to post
Share on other sites
I noticed that the prototype for your constructor changed in your posts. Are you sure the prototype declared in the class matches the out of class definition?

Share this post


Link to post
Share on other sites
quote:
Original post by SiCrane
I noticed that the prototype for your constructor changed in your posts. Are you sure the prototype declared in the class matches the out of class definition?


Yes I am sure.
Still, I dont know what cause these errors ?
How come it says that I redfine the type DATA?
Please help.

Share this post


Link to post
Share on other sites
I''m willing to bet you didn''t read my post carefully.
Correct:

template <class DATA>
DataListLink<DATA>::DataListLink (int Index, const DATA & Data)

Incorrect:

template <class DATA>
DataListLink<class DATA>::DataListLink (int Index, const DATA & Data)

(Fruny, I blame you. )

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!