A
alexroat
Hi, when I'm trying to compile this code with gcc 4 I get this strange
error :
alex@deimos:~/Desktop/Image$ make -k Image
g++ Image.cpp -o Image
Image.cpp:29: error: expected initializer before 'Image'
make: *** [Image] Error 1
The code of the source of Image.cpp is the following:
#include <iostream>
template <class T>
class Image
{
public:
class Handler
{
public:
private:
Handler(class Image &i);
friend class Image;
};
const Handler operator()();
private:
};
template <class T>
const Image<T>::Handler Image<T>:
perator()()
{
return Handler(*this);
}
template <class T>
Image<T>::Handler::Handler(class Image<T> &i)
{
}
typedef unsigned char byte;
int main()
{
Image <byte> i1;
}
The problem seems to be not present if I remove the template leaving
as a common class the Image one. I think it's due by the fact that
compiler cannot predict the form of Handler before it has not been
istantiated ... but I'm not sure ... could you help me ?
Is a solution to templatizate also the Handler class and moreover move
it outside the Image class ?
Thank you in advance.
Alessandro
error :
alex@deimos:~/Desktop/Image$ make -k Image
g++ Image.cpp -o Image
Image.cpp:29: error: expected initializer before 'Image'
make: *** [Image] Error 1
The code of the source of Image.cpp is the following:
#include <iostream>
template <class T>
class Image
{
public:
class Handler
{
public:
private:
Handler(class Image &i);
friend class Image;
};
const Handler operator()();
private:
};
template <class T>
const Image<T>::Handler Image<T>:
{
return Handler(*this);
}
template <class T>
Image<T>::Handler::Handler(class Image<T> &i)
{
}
typedef unsigned char byte;
int main()
{
Image <byte> i1;
}
The problem seems to be not present if I remove the template leaving
as a common class the Image one. I think it's due by the fact that
compiler cannot predict the form of Handler before it has not been
istantiated ... but I'm not sure ... could you help me ?
Is a solution to templatizate also the Handler class and moreover move
it outside the Image class ?
Thank you in advance.
Alessandro