473,395 Members | 1,658 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,395 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 1972

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.