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

Template resolution problem

Hi All,

I am facing a problem with a piece of code which compiles and
works on windows. but it does not compile on g++. I am trying to figure
out is it a problem with the code which does not adhere to C++ standard
and windows compiler is not strict on that. I am using g++ version
3.2.3. Is the code correct? If not please advise.
#include<iostream.h>

class Employee
{
public:
static void showError()
{
cout<<"this shows error"<<endl;
}
};

template <class ItemType>
class MyContainer
{
public:
ItemType add(ItemType a, ItemType b);
};
class ASLDAPServices
{
public:
template <class MemberType>
MemberType add(MemberType a, MemberType b);

};
template <class MemberType>
MemberType ASLDAPServices::add(MemberType a, MemberType b)
{
return a+b;
}

class ASLDAPGroup
{
public:
template <class MemberType>
void addIt()
{
ASLDAPServices ad;
MemberType i = ad.add<MemberType>(12,34);
cout<<i<<endl;

}
};

int main()
{

ASLDAPGroup grp;
grp.addIt<int>();
return 0;
}

$ g++ -o test1 test1.cpp
In file included from /usr/include/c++/3.2.3/backward/iostream.h:31,
from test1.cpp:1:
/usr/include/c++/3.2.3/backward/backward_warning.h:32:2: warning:
#warning This file includes at least one deprecated or antiquated
header. Please consider using one of the 32 headers found in section
17.4.1.2 of the C++ standard. Examples include substituting the <X>
header for the <X.h> header for C++ includes, or <sstream> instead of
the deprecated header <strstream.h>. To disable this warning
use -Wno-deprecated.
test1.cpp: In member function `void ASLDAPGroup::addIt()':
test1.cpp:44: syntax error before `;' token
Regards,
Mohan.

Jul 23 '05 #1
4 1361
"Mohanasundaram" <mo*********************@gmail.com> wrote...
I am facing a problem with a piece of code which compiles and
works on windows. but it does not compile on g++. I am trying to figure
out is it a problem with the code which does not adhere to C++ standard
and windows compiler is not strict on that. I am using g++ version
3.2.3. Is the code correct? If not please advise.
#include<iostream.h>
#include <iostream>
using std::cout;
using std::endl;

class Employee
{
public:
static void showError()
{
cout<<"this shows error"<<endl;
}
};

template <class ItemType>
class MyContainer
{
public:
ItemType add(ItemType a, ItemType b);
};
class ASLDAPServices
{
public:
template <class MemberType>
MemberType add(MemberType a, MemberType b);

};
template <class MemberType>
MemberType ASLDAPServices::add(MemberType a, MemberType b)
template<class MemberType>
MemberType ASLDAPServices<MemberType>::add( ...
{
return a+b;
}

class ASLDAPGroup
{
public:
template <class MemberType>
void addIt()
{
ASLDAPServices ad;
MemberType i = ad.add<MemberType>(12,34);
cout<<i<<endl;

}
};

int main()
{

ASLDAPGroup grp;
grp.addIt<int>();
return 0;
}

$ g++ -o test1 test1.cpp
In file included from /usr/include/c++/3.2.3/backward/iostream.h:31,
from test1.cpp:1:
/usr/include/c++/3.2.3/backward/backward_warning.h:32:2: warning:
#warning This file includes at least one deprecated or antiquated
header. Please consider using one of the 32 headers found in section
17.4.1.2 of the C++ standard. Examples include substituting the <X>
header for the <X.h> header for C++ includes, or <sstream> instead of
the deprecated header <strstream.h>. To disable this warning
use -Wno-deprecated.
test1.cpp: In member function `void ASLDAPGroup::addIt()':
test1.cpp:44: syntax error before `;' token


Which one is line 44? You have at least 3 lines in that function that
end on a semicolon. Why do we have to guess?

V
Jul 23 '05 #2
Hi Victor,

Sorry for that
Here is that line
MemberType i = ad.add<MemberType>(12,34);

Regards,
Mohan.

Jul 23 '05 #3
Hi Victor,
I changed the code as per your suggestion but it is giving the
following error

Changed code:
----------------------
template <class MemberType>
MemberType ASLDAPServices<MemberType>::add(MemberType a, MemberType b)
{
return a+b;
}

error:
-------
$ g++ -o test1 test1.cpp
In file included from /usr/include/c++/3.2.3/backward/iostream.h:31,
from test1.cpp:1:
/usr/include/c++/3.2.3/backward/backward_warning.h:32:2: warning:
#warning This file includes at least one deprecated or antiquated
header. Please consider using one of the 32 headers found in section
17.4.1.2 of the C++ standard. Examples include substituting the <X>
header for the <X.h> header for C++ includes, or <sstream> instead of
the deprecated header <strstream.h>. To disable this warning
use -Wno-deprecated.
test1.cpp:32: non-template type `ASLDAPServices' used as a template
test1.cpp: In member function `void ASLDAPGroup::addIt() [with
MemberType =
int]':
test1.cpp:53: instantiated from here
test1.cpp:44: no matching function for call to
`ASLDAPServices::add(int, int)'
$

Jul 23 '05 #4
"Mohanasundaram" <mo*********************@gmail.com> wrote...
Hi Victor,
I changed the code as per your suggestion but it is giving the
following error

Changed code:
----------------------
template <class MemberType>
MemberType ASLDAPServices<MemberType>::add(MemberType a, MemberType b)
{
return a+b;
}
My bad. Should be

template<class MemberType>
MemberType ASLDAPServices::add<MemberType>(MemberType a, MemberType b)
....
[...]


V
Jul 23 '05 #5

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

Similar topics

1
by: Joachim Spoerhase | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I am a XSLT-beginner and i read the XSLT-recommendation of the W3C through. But I did'nt really understand section 5.5 of the latest...
14
by: Gianni Mariani | last post by:
Does anyone know if this is supposed to work ? template <unsigned N> int strn( const char str ) { return N; } #include <iostream>
2
by: Xenos | last post by:
The new version of GCC is out and in its list of changes, it talks about the C++ Standard's requirements for using the typename and template keywords to disambiguate dependent names. I'm use to...
1
by: Adam Dziendziel | last post by:
Hi all! I'm writing a luabind/boost::python-like binding utility for a Squirrel language to generating wrapper-functions for C++ classes and have a problem with passing the pointer-to-member...
7
by: Tony Johansson | last post by:
Hello Experts! I have the following Array template class see below. I execute these three statements statement 1: Array<int> x(5); statement 2: cin >>x; statement 3: Array<int>::element_type ...
5
by: lobequadrat | last post by:
Hello, I am trying to get the following code work (unfortunately not mine ... :( ) template <class Tclass Test { public: class ELEM;
3
by: StephQ | last post by:
In utility.hpp I have: namespace utility { template <class T, double (T::*F)(double) const> class Display { private: static double resolution;
16
by: xman | last post by:
I defined namespace hpc in main.cpp, so not to clash with other libraries. But I found that, in namespace boo, instantiating a template with a class in namespace hpc, causes compilation errors by...
11
by: mathieu | last post by:
Hi there, I don't think I'll be able to describe my issue correctly, so instead I'll just give a pseudo C++ code I am struggling with. Basically I am looking for a 'pure virtual template'...
32
by: Stephen Horne | last post by:
I've been using Visual C++ 2003 for some time, and recently started working on making my code compile in GCC and MinGW. I hit on lots of unexpected problems which boil down to the same template...
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
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.