I
ik
Hello All,
I am facing problem with classes having some functions as templates. Is
it a limitation of C++ templates not to have class functions as
templates ? I am attaching the code below, I am not able to complie. I
tried with VC++ and MingW. Can somebody help me ?
#include <iostream>
#include <string>
#include <vector>
class A {
public:
A();
~A();
template <typename T>
void foo(const std::wstring & name, std::vector<T> const &
vecAttrValues);
};
A::A()
{
}
A::~A()
{
}
template <typename T>
void A::foo(const std::wstring & name, std::vector<T> const &
vecAttrValues)
{
std::vector<T>::const_iterator it;
std::vector<T>::const_iterator itEnd = vecAttrValues.end();
for(it = vecAttrValues.begin(); it != itEnd; it++)
{
// Some thing
}
}
template <typename T>
void foog(const std::wstring & name, std::vector<T> const &
vecAttrValues)
{
std::vector<T>::const_iterator it;
std::vector<T>::const_iterator itEnd = vecAttrValues.end();
for(it = vecAttrValues.begin(); it != itEnd; it++)
{
// Some thing
}
}
int main(int argc, char* argv[])
{
std::wstring wstrName(L"My Name");
std::vector<int> vecInts;
A a;
a.foo (wstrName, vecInts);
foog (wstrName, vecInts);
return 0;
}
Note that foog which is the global version of foo, will compile with
out any problem, but foo cannot be compiled.
Thanks
IK.
I am facing problem with classes having some functions as templates. Is
it a limitation of C++ templates not to have class functions as
templates ? I am attaching the code below, I am not able to complie. I
tried with VC++ and MingW. Can somebody help me ?
#include <iostream>
#include <string>
#include <vector>
class A {
public:
A();
~A();
template <typename T>
void foo(const std::wstring & name, std::vector<T> const &
vecAttrValues);
};
A::A()
{
}
A::~A()
{
}
template <typename T>
void A::foo(const std::wstring & name, std::vector<T> const &
vecAttrValues)
{
std::vector<T>::const_iterator it;
std::vector<T>::const_iterator itEnd = vecAttrValues.end();
for(it = vecAttrValues.begin(); it != itEnd; it++)
{
// Some thing
}
}
template <typename T>
void foog(const std::wstring & name, std::vector<T> const &
vecAttrValues)
{
std::vector<T>::const_iterator it;
std::vector<T>::const_iterator itEnd = vecAttrValues.end();
for(it = vecAttrValues.begin(); it != itEnd; it++)
{
// Some thing
}
}
int main(int argc, char* argv[])
{
std::wstring wstrName(L"My Name");
std::vector<int> vecInts;
A a;
a.foo (wstrName, vecInts);
foog (wstrName, vecInts);
return 0;
}
Note that foog which is the global version of foo, will compile with
out any problem, but foo cannot be compiled.
Thanks
IK.