By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,421 Members | 1,127 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,421 IT Pros & Developers. It's quick & easy.

A question regarding templates

P: n/a
This is quite fundamental. So I apologize if it has already been
discussed.
From what I understand, a template declaration and definition is

generally in the same file. (like the standard vector file). So does it
mean there is no way a class can be exposed as a template without
giving out the source? For eg,

template<class T>
class myClass{
public:
void func(T input) ;
};
template<class T>
void myClass<T>::func(T input)
{ /* function definition here...*/}

Let us say someone wants to write a library which implements myClass so
that anyone can use myClass by instantiating the template with the
required type. Is there anyway, that the library can be supplied
without the user having access to source code of "func" method ? I know
this is not a realistic scenario but I dont think it is far fetched to
imagine a good scenario where the auther of the main template may not
want the users to see the code.

Jun 21 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
vi************@yahoo.com schrieb:
This is quite fundamental. So I apologize if it has already been
discussed.
From what I understand, a template declaration and definition is

generally in the same file. (like the standard vector file). So does it
mean there is no way a class can be exposed as a template without
giving out the source? For eg,

template<class T>
class myClass{
public:
void func(T input) ;
};
template<class T>
void myClass<T>::func(T input)
{ /* function definition here...*/}

Let us say someone wants to write a library which implements myClass so
that anyone can use myClass by instantiating the template with the
required type. Is there anyway, that the library can be supplied
without the user having access to source code of "func" method ? I know
this is not a realistic scenario but I dont think it is far fetched to
imagine a good scenario where the auther of the main template may not
want the users to see the code.


http://www.parashift.com/c++-faq-lit...html#faq-35.12

HTH
/S
--
Stefan Naewe
naewe.s_AT_atlas_DOT_de
Jun 21 '06 #2

P: n/a
>
http://www.parashift.com/c++-faq-lit...html#faq-35.12


hi Stefan,

I kind of knew the "why" part of it. But the 35.13 section gives a
decent hack and is definitely useful (of course, not very practical
...in the sense I will have to keep adding an entry to the cpp file for
every new template instantiation type. ). Thanks for the link

--Vikram

Jun 21 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.