473,387 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

A question regarding templates

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
2 1142
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
>
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Fred H | last post by:
I'm currently trying to write a function template that can fill a variable of arbitrary type with 'random' stuff, but I can't seem to get my function template working. In my .h file I've...
2
by: karlman | last post by:
Hello! Here's a question regarding templates: Suppose I have these three files containing the following: print.hpp: template < typename T > void print( T x ); print.cpp: template <typename...
3
by: darkstorm | last post by:
I have a doubt regarding inheritance involving templates Consider this: ///////////////////////////////////// template<typename T> class A { private: T m_a;
2
by: Mr.Tickle | last post by:
So whats the deal here regarding Generics in the 2004 release and templates currently in C++?
5
by: Eric Fortier | last post by:
Hi all, Last year I posted a message regarding templates use in blitter functions, but the single answer I got didn't help. My problem is that I was writing blitter functions which takes a...
3
by: zvirack | last post by:
Hi, I am trying to create a class that can write any type of object to a file. I would like to use a template function which is a member of the class. Something like: class MyWriter {...
5
by: sam_cit | last post by:
Hi Everyone, Its know that c++ compiler instantiates a new version of the function/class when it sees a usage of a function/class template with a particular data type, assuming that c++ supports...
3
by: Johs | last post by:
I have read that when you are using templates you are making generic programs. But I don't see whats so generic about templates. You can make generic programs without templates through the use of...
6
by: thorsten.schilling | last post by:
Hello everybody, the question is, what is the "golden way" or the best way, if I have a memberfunction in a class, which should return a new instance of an object. For example some class Foo...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.