C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Template resolution problem

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Mohanasundaram
Guest





PostPosted: Fri Feb 25, 2005 2:09 pm    Post subject: Template resolution problem Reply with quote



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"< }
};

template 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<
}
};

int main()
{

ASLDAPGroup grp;
grp.addIt 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.

Back to top
Victor Bazarov
Guest





PostPosted: Fri Feb 25, 2005 2:15 pm    Post subject: Re: Template resolution problem Reply with quote



"Mohanasundaram" <mohanasundaram.chandran (AT) gmail (DOT) com> wrote...
Quote:
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 using std::cout;
using std::endl;

Quote:

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

template class MyContainer
{
public:


ItemType add(ItemType a, ItemType b);


};


class ASLDAPServices
{
public:
template MemberType add(MemberType a, MemberType b);

};
template MemberType ASLDAPServices::add(MemberType a, MemberType b)

template MemberType ASLDAPServices<MemberType>::add( ...

Quote:
{
return a+b;
}

class ASLDAPGroup
{
public:
template <class MemberType
void addIt()
{
ASLDAPServices ad;
MemberType i = ad.add cout<
}
};

int main()
{

ASLDAPGroup grp;
grp.addIt 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 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



Back to top
Mohanasundaram
Guest





PostPosted: Fri Feb 25, 2005 2:18 pm    Post subject: Re: Template resolution problem Reply with quote



Hi Victor,

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

Regards,
Mohan.

Back to top
Mohanasundaram
Guest





PostPosted: Fri Feb 25, 2005 2:29 pm    Post subject: Re: Template resolution problem Reply with quote

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)'
$

Back to top
Victor Bazarov
Guest





PostPosted: Fri Feb 25, 2005 3:44 pm    Post subject: Re: Template resolution problem Reply with quote

"Mohanasundaram" <mohanasundaram.chandran (AT) gmail (DOT) com> wrote...
Quote:
Hi Victor,
I changed the code as per your suggestion but it is giving the
following error

Changed code:
----------------------
template <class MemberType
MemberType ASLDAPServices {
return a+b;
}

My bad. Should be

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

Quote:
[...]

V



Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.