Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Function Template Problem

Posted on 2006-11-12
6
Medium Priority
?
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: 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

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

719 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