Sign in to follow this  
  • entries
    570
  • comments
    2427
  • views
    216192

Untitled

Sign in to follow this  

94 views

So in my CS class today we went over class templates and such. Part of the demonstration involved a command-line compilation in UNIX and then an examination of the generated object files (which I thought was really cool).

The sad part was when we got to separate compilation issues. She basically said there's 2 ways to get around this -
  1. Explicitly declare the template class types in the *.cpp which includes the template class implementation.

  2. Include the template class implementation *.cpp at the end of the template header.

I was like "..." and raised my hand to bitch about it, but she didn't see me apparently and went on to the next topic and I was like "sigh".

I hope she doesn't do that stuff in production code.
Sign in to follow this  


5 Comments


Recommended Comments

Still, you should have bitched about it[lol]

The more you wait the better. Sometimes it is better to correct you teachers waay after they make a mistake

Share this comment


Link to comment
Yeah, I usually send an anonymous email after class with, essentially, lecture errata but I've been too lazy to take notes on the things I thought were wrong (to look them up later, and enumerate with citations).

*shrug*

Share this comment


Link to comment
The proper way to seperate template declaration from template definition is to use the export keyword. Unfortunatly, it does not do what you think, and it's unlikely your compiler supports it.

So she should have just stuck the template definitions in the header like everyone else. The way she did, the whole class is thinking 'wtf, so what good are they then?'

Share this comment


Link to comment
Well I mean, from what I understand it works if you explicitly instantiate specific classes from the template. Which is completely stupid.

The problem could be easily solved by just putting the template class declaration in one header file, then including another header file which had the implementation. Keeps the damned narrow-minded "1 CLASS 2 FILES" ideal and still actually works without killing the usefulness of templates.

Oh well. I don't think more than 3 or 4 people in the class actually understand wtf templates are doing at this point anyway, so its not that big of a deal. You really can't just learn C++ from 4 or 5 easy lectures :P

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now