Skip to main content
gamedev.net
🔒 Locked

Template Issues (again)

Started by Normie 4 replies 400+ views
Original Post
Normie
Normie
I''ve got a templated binary tree class. The whole thing works when the declaration and definitions are in the same header file, but if I try to separate them into 2 files (like my mind is screaming at me to do out of habit right now ), it just doesn''t go. I''m aware that this is a template issue, but I''ve searched the forums, and I can''t really figure out what to do about it. Any way to get my class to work with the declaration and definition separated? -Normie
I am a devout follower of the"Lazy Programmer's Doctrime"(tm)...and I'm damned proud of it, too!-----"I came, I saw, I started makinggames." ... If you'll excuseme, I must resume my searchfor my long lost lobotomy stitches.
Spiral
Spiral
You could put the implementation into another file (.ctt is a common extension, IIRC) and #include it into the bottom of your header file, under the class declaration.
--------------------Go Stick Your Head In A Pig
sbennett
sbennett
I''m not sure of this, but if your class declaration says

template
class...

then put ''template'' in front of the definition of every method in your .cpp implementation file. I don''t know, maybe you''ve done this, but it might solve your problem.
Normie
Normie
quote:

You could put the implementation into another file (.ctt is a common extension, IIRC) and #include it into the bottom of your header file, under the class declaration.



So, wait, the .h file and the .ctt (or .cpp, or whatever) include each other? Isn''t that a circular definition?

Not to mention, there''s another problem: I have a pair of ''helper'' global functions declared in the header, and defined in the cpp. This going to hurt anything?

-Normie
I am a devout follower of the"Lazy Programmer's Doctrime"(tm)...and I'm damned proud of it, too!-----"I came, I saw, I started makinggames." ... If you'll excuseme, I must resume my searchfor my long lost lobotomy stitches.
Spiral
Spiral
quote:
Original post by Normie
So, wait, the .h file and the .ctt (or .cpp, or whatever) include each other? Isn''t that a circular definition?



Dont #include your header file in the .ctt file.

quote:

Not to mention, there''s another problem: I have a pair of ''helper'' global functions declared in the header, and defined in the cpp. This going to hurt anything?



I cant think of any reason why not. Best way to find out is to try it.
--------------------Go Stick Your Head In A Pig

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.