Archived

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

Templated Functions

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

If I include the following header file
  
template <typename Z> class bar {
	public :
		Z a;

	bar(Z b) : a(b) { }
	
	~bar() {}
};

template <typename Z> bar<Z> ram(Z a) {
	return bar<Z>(a);
}

bar<int> ewe(int a) {
	return bar<int>(a);
}
  
in seperate source files the linker naturally complains about the multiply defined symbol ewe. However it doesn''t complain about the templated function ram. Why is this exactly?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I''m pretty sure that...
(not positive)
templates are not actual code until they are used somewhere, ie they are instianited (sp?). In fact, as I remember, in the Standard, I don''t think the template is even supposed to be compiled
So, because Ewe isn''t a template function, then it _is_ defined, and multiple defines are obviously not allowed..
however for Ram, it doesn''t exist until it is used, so you could indeed include it many many times

I think.

C++Freak
(so I''m too lazy to change my password so I can log in again)

Share this post


Link to post
Share on other sites