Solved

Function Template Problem

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
PCH Sample and Makefile 14 71
Compile GLUT with Visual Studio 2015 1 85
Path to  STL Map header file 1 29
Safe conversion? 4 21
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now