![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Professional Programmer
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 377
Rep Power: 0
![]() |
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
}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! |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Jun 2006
Location: Ireland
Posts: 152
Rep Power: 3
![]() |
Too tired to phrase an intelligent answer to the first but this link seems to do a good job at explaining the details.
On the second question, well for your example it is largely just a matter of taste, but again the mentioned link goes more into the specifics.
__________________
Visit my website BinaryNotions. |
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
can't give any cool details...BUT i've been told that when you use templates the declarations and definitions need to be in one file.
the reason you find weird shit like this is that C++ is not a ground-up new language. it's a wrapper for C. so add-on crap like templates involves weird shit so they don't have to rewrite the whole compiler. you just gotta live with it. good luck!
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 377
Rep Power: 0
![]() |
Thanks for the info guys. Is there any difference at all if I define the function inline or outside of the class definition?
__________________
I am Addicted to Linux! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |