473,324 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Template methods, declaration and Implementation in header file andoverloaded methods.

Hi ,

Since, i did not want to write instantiations in Source file of all
template methods for various different datatypes that my client might
use, i choose to write implementation of template methods along with
their declarations in the header file. Well, there are also other
files in the project, which include this header file as well, which
all gets compiled, linked and tested well.

#ifndef __ATT_H__
#define __ATT_H__
namespace TESTSPACE
{

class Att : public Abs
{

public:
template<class T>
unsigned long read(T& start, unsigned long count=0)
{
//Implementation written here
}
unsigned long read(std::back_insert_iterator< vector<std::string&
start, unsigned long count=0)
{
//Implementation written here
}
template<class T>
unsigned long write(T& start, T& stop)
{
//Implementation written here
}
unsigned long write(vector <std::string>::iterator& start, vector
<std::string>::iterator& stop)
{
//Implementation written here
}

};

#endif


However, to keep the header file look more reader friendly with just
declarations and moving all the implementation towards the end of the
header file as given below, however generates me errors as
"error C2373: 'TESTSPACE::Att::read' : redefinition; different type
modifiers.
What am i missing here ? The template functions are basically
overloaded methods, then why does the compiler throw error for the
below code ?
#ifndef __ATT_H__
#define __ATT_H__
namespace TESTSPACE
{

class Att : public Abs
{

public:
template<class T>
unsigned long read(T& start, unsigned long count=0);
unsigned long read(std::back_insert_iterator< vector<std::string&
start, unsigned long count=0);
template<class T>
unsigned long write(T& start, T& stop);
unsigned long write(vector <std::string>::iterator& start, vector
<std::string>::iterator& stop);

};

//All implementations done here temporarily
//Move below code to a separate "impl.h" file later
template<class T>
unsigned long Att::read(T& start, unsigned long count)
{
//Implementation written here
}
unsigned long Att::read(std::back_insert_iterator<
vector<std::string& start, unsigned long count)
{
//Implementation written here
}
template<class T>
unsigned long Att::write(T& start, T& stop)
{
//Implementation written here
}
unsigned long Att::write(vector <std::string>::iterator& start,
vector <std::string>::iterator& stop)
{
//Implementation written here
}

#endif

Jun 27 '08 #1
0 1969

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Nomak | last post by:
Hello all, i have two template classes which needs each other. I tried to write some fwd decl / decl / impl in a good way but i can't get it to compile. Explanations: - .hh files are for...
2
by: Ruben Campos | last post by:
I have a problem with a template function that is declared as a friend of a template class. I'll first show the exact problem with source code: // MyClass.hpp template <typename T> class...
2
by: Jessica | last post by:
I have a base class and a derived class, but I am getting errors when I try to access functions of the derived class. Simplified version of my code is as follows: //////////////// // test2.hh...
3
by: Veeru | last post by:
i have one structure SPageDetails. i have a template class CStack. Now i have a pointer of this stack class in another class "CAnotherClass" as: class CAnotherClass {...
14
by: Jess | last post by:
Hello, I was told that if I have a template class or template function, then the definitions must be put into the header file where I put the declarations. On the other hand, it is generally...
13
by: mike b | last post by:
Hello everyone, thanks in advance for your help. I'm new to C++ templates and have run into some issues using member function templates. I have a shared library containing templates that I'm...
8
by: Tim Frink | last post by:
Hi, I want to use a callback function together with templates. Let's say I've this code: File a.h: class A { private:
0
by: anto.anish | last post by:
Hi , Since, i did not want to write all instantiations in Source file of all template methods for various different datatypes that my client might use, Instead, i choose to write implementation...
1
by: anto.anish | last post by:
Hi , Since, i did not want to write explicit instantiations in Source file of all template methods for various different datatypes that my client might use, i choose to write implementation of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.