473,387 Members | 1,379 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,387 software developers and data experts.

Template methods - avoiding instantiation, declaration andimplementation in header file

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 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, 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 template methods, then why does the compiler throw error
for the above 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

What am i missing here ? The template functions are basically
overloaded methods, then why does the compiler throw error for the
above code ?

Thanks
Jun 27 '08 #1
0 1329

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

Similar topics

15
by: iuweriur | last post by:
A few questions on the curiously recurring template pattern: This page: http://c2.com/cgi/wiki?CuriouslyRecurringTemplate this part: template<typename T> struct ArithmeticType { T operator...
3
by: Patrick Guio | last post by:
Hi, I have trouble to compile the following piece of code with g++3.4 but not with earlier version // Foo.h template<typename T> class Foo { public:
4
by: Alfonso Morra | last post by:
Does VC 7.1 support template specialization and partial specialization ?
3
by: sks | last post by:
Hello all Is the usage of extern keyword valid for telling the compiler to NOT instantiate a template and to link it from an another binary? For example: Suppose module A's binary contains a...
5
by: Sunny | last post by:
Hi, I want to create a library out of a C++ sources. The implementation should be in object files and there will be a header file which the client will #include. I want to use templates to...
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...
0
by: anto.anish | last post by:
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...
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...
5
by: chgans | last post by:
Hi all, I'm having difficulties with some template static member, especially when this member is a template instance, for example: ---- template<typename T> class BaseT { public: static...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.