J
Jess
Hi,
I have a template function that triggered some compiler error. The
abridged version of the class and function is:
#include<memory>
using namespace std;
template <class T>
class Vec{
public:
T* data;
T* avail;
T* limit;
std::allocator<T> alloc;
template<class In> void create (In,In);
};
template<class T,class In>
void Vec<T>::create(In i, In j){
data = alloc.allocate(j - i);
limit = avail = std::uninitialized_copy(i,j,data);
}
The compiler error was:
error: prototype for 'void Vec<T>::create(In, In)' does not match any
in class 'Vec<T>'
error: candidate is: template<class T> template<class In> void
Vec::create(In, In)
error: template definition of non-template 'void Vec<T>::create(In,
In)'
Another finding I have is that if I change the template function to:
template<class In, class T>
void Vec<T>::create(In i, In j){
data = alloc.allocate(j - i);
limit = avail = std::uninitialized_copy(i,j,data);
}
Then I get this even stranger error (because it says what I've
declared aren't available)
error: invalid use of undefined type 'class Vec<T>'
error: declaration of 'class Vec<T>'
error: template definition of non-template 'void Vec<T>::create(In,
In)'
In member function 'void Vec<T>::create(In, In)':
error: 'data' was not declared in this scope
error: 'alloc' was not declared in this scope
error: 'limit' was not declared in this scope
error: 'avail' was not declared in this scope
I guess I must have made some mistakes with the order of these type
parameters. Can someone please point out my mistakes?
Thanks,
Jess
I have a template function that triggered some compiler error. The
abridged version of the class and function is:
#include<memory>
using namespace std;
template <class T>
class Vec{
public:
T* data;
T* avail;
T* limit;
std::allocator<T> alloc;
template<class In> void create (In,In);
};
template<class T,class In>
void Vec<T>::create(In i, In j){
data = alloc.allocate(j - i);
limit = avail = std::uninitialized_copy(i,j,data);
}
The compiler error was:
error: prototype for 'void Vec<T>::create(In, In)' does not match any
in class 'Vec<T>'
error: candidate is: template<class T> template<class In> void
Vec::create(In, In)
error: template definition of non-template 'void Vec<T>::create(In,
In)'
Another finding I have is that if I change the template function to:
template<class In, class T>
void Vec<T>::create(In i, In j){
data = alloc.allocate(j - i);
limit = avail = std::uninitialized_copy(i,j,data);
}
Then I get this even stranger error (because it says what I've
declared aren't available)
error: invalid use of undefined type 'class Vec<T>'
error: declaration of 'class Vec<T>'
error: template definition of non-template 'void Vec<T>::create(In,
In)'
In member function 'void Vec<T>::create(In, In)':
error: 'data' was not declared in this scope
error: 'alloc' was not declared in this scope
error: 'limit' was not declared in this scope
error: 'avail' was not declared in this scope
I guess I must have made some mistakes with the order of these type
parameters. Can someone please point out my mistakes?
Thanks,
Jess