Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Feb 1st, 2007, 6:43 PM   #1
King
Professional Programmer
 
King's Avatar
 
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 377
Rep Power: 0 King is an unknown quantity at this point
Template Questions

I just have a few questions about templates. I will just use the following class as an example to use for my questions:
template <class T>
class MyClass
{
public:
	MyClass() {};
	~MyClass() {};
	void MyFunction(const T &);
};

template<class T>
void MyClass<T>::MyFunction(const T &value)
{
	// do something
}
Usually when I write a class I would put the implementation of the functions in a separate .cpp file, but when I do this I get compile errors. But if I put the implementation of the function in the same file as the class definition it works fine, why is that?
My second question is if I have to keep the implementation of my functions in the same file, would there be a point to still define it outside if the class definition like I have shown above, or should I just define it inside the class?
Thanks.
__________________
I am Addicted to Linux!
King is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
friends, templates, and other s**t bl00dninja C++ 4 Oct 14th, 2006 1:15 AM
Help: Template Class' copy constructor MicahCarrick C++ 2 Jan 23rd, 2006 5:33 AM
Function Template Question aznluvsmc C++ 6 Oct 7th, 2005 11:37 PM
Template + operator problem Polyphemus_ C++ 3 Sep 30th, 2005 6:43 PM
nontype default template parameters earl C++ 4 Jun 21st, 2005 11:27 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:03 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC