Advertisement

Need Help with templates

Started by June 21, 2002 12:34 PM
11 comments, last by Raskolnikov 22 years, 5 months ago
quote: Original post by Oluseyi
Incidentally, I''ve heard rumors that removing export from the next iteration of the C++ Standard is under consideration...


Those poor coders at EDG are going to scream.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"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
Debugging templates is a nightmare. Write a (or several) non template version(s) of your class with concrete types and debug them. Then convert one of them to a template.

Either that or you can stick a lot of "cout << "The error is not here";" statements in your template.

If you go back and reread the quote I posted earlier, you'll see why you can't see source code for templates. The code is generated dynamically for the type you specify (which is probably in assembly, but don't take my word on that). Your template code, as it is, is never actually compiled and linked into your program. The compiler actually "spawns" an instance of your class for a concrete type every time you create an object of your class with a different type. Say if you do something like:

CClass < int > x;CClass < char > y;CClass < CWhatever > z;    


the compiler actually spits out 3 seperate classes for you following your template.

[edit] Stupid HTML...

[edit2] P.S. Don't give up on templates! They're really cool once you get the hang of them (kinda like pointers).

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/

[edited by - Chem0sh on June 23, 2002 1:33:23 AM]

[edited by - Chem0sh on June 23, 2002 1:36:15 AM]

[edited by - Chem0sh on June 23, 2002 1:36:45 AM]
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/
Advertisement
I am not giving up on templates. I learned how to program using gcc so I am used to using cout to debug. The template functions end up going directy to assembly which is what you see if you try to debug them. It seems to me that the compiler could generate source code then compile it allowing templates to be debugged.

This topic is closed to new replies.

Advertisement