Solved

Function Template Problem

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Retrieve PID of MicrosoftEdge.exe with GetForegroundWindow() 6 152
Compile GLUT with Visual Studio 2015 1 148
Find Visual Studio Tools 2 103
Safe conversion? 4 68
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 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 viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

777 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