Solved

Function Template Problem

Posted on 2006-11-12
6
241 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 125 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 125 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

840 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