M
Mohanasundaram
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.
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.