Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Function Template Problem

Posted on 2006-11-12
6
Medium Priority
?
268 Views
Last Modified: 2010-04-01
Ok guys i am having a function template problem here:

Basically and finally (after a huge WORKOUT!!!) i have 5 files all working...

OrderedList.h & .cc
Member.h & .cc
Node.h & .cc
ClubTable.h & .cc  - Basically the HashTable
and finally the main.cc


Now the problem is that where do i actually put the function templates - in the .cc of the upper files or the main.cc??
Thats the first question the rest will follow on.

0
Comment
Question by:junaid_raja30
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 17926295
Put them in a separate header (.h) file that is included by all the .cc files that need to use the function templates, otherwise you probably will get linker errors.
0
 

Author Comment

by:junaid_raja30
ID: 17926388
there is no separate header file? i mean we have a question here in a book.... it says that

how could your program be adapted to using templates which deals with any data type?
0
 
LVL 86

Expert Comment

by:jkr
ID: 17926621
>>there is no separate header file?

Then create one or put them in a .h file that is included in all .cc files anyway.
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 500 total points
ID: 17929042
>>there is no separate header file?

if there is only one main.cc you can put all into that file.

That is ok for assignment projects where you don't use the classes/structs of previous lessions. But if you have the requirement to reuse the classes in further projects or if you use more than one cpp/cc file, you *have* to put the class definitions to separate header files which can be included by any cpp/cc file. In case of template classes put the implementation to the header file as well - as already told above - cause the implementation was needed for any concrete template type used.

When creating header files you should protect them for getting included twice by adding

#ifndef  HEADERFILENAME_H
#define HEADERFILENAME_H

put here all the rest
...

#endif // HEADERFILENAME_H

Regards, Alex
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question