Archived

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

Templates?

This topic is 5617 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

a simple thing. and it has tons of features and huge power. and is loved and hated like that. the simple idea is to template parameters. like this:


  
template<typename SomeType>
class Twin {
SomeType first_twin;
SomeType second_twin;
};

class Object;//some object


void main() {
Twin<int> int_twin; //generate a twin of ints

int_twin.first_twin is an int, and you can use it as int;
int_twin.second_twin is an int as well..;
Twin<Object> obj_twin; //generate a twin of objects

obj_twin.first_twin is here an 'Object';
obj_twin.second_twin as well..;
}


the power of this?
at first: general containers like some dynamic arrays..


  
#include <vector>
...
vector<Object> object_array; //creates a dynamic sizeable array of Objects

Object x; //creates an Object

object_array.push_back(x); //adds the Object to the array



hope you get the idea.. the power of this, you'll learn yourself. if you need...

"take a look around" - limp bizkit
www.google.com

[edited by - davepermen on July 25, 2002 7:54:49 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by lone_ranger
I have the c++ book "C++ the complete reference 2nd edition" 1990


You really, really need a newer book if you are serious about learning C++. Anything published earlier than 1999 should be considered suspect.




"The churches used to win their arguments against atheism, agnosticism, and other burning issues by burning the ismists, which is fine proof that there is a devil but hardly evidence that there is a God."
Ben Lindsey and Wainwright Evans

Share this post


Link to post
Share on other sites
quote:
Original post by Arild Fines
You really, really need a newer book if you are serious about learning C++. Anything published earlier than 1999 should be considered suspect.



I was going to say the same thing, the language was still significantly evolving until mid 1995, settled down a bit, and was finally standardized in late 1998.

(And Microsoft still hasn't implemented a reasonably compliant compiler, nearly four years later.)

[edited by - Magmai Kai Holmlor on July 25, 2002 8:52:49 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
put that book in your history section, you know the shelf with books on ancient Rome and the Middle Ages. Then buy "The C++ Programming Language 3rd/special edition" by Bjarne Stroustrup, the creator of the language.

Share this post


Link to post
Share on other sites