Specialization of a method from an imbricated template class

J

Julien Jorge

Hi,

I have a compilation-time error on the specialization of a method from a imbricated template class, and I can't figure why. The problematic part of the code is resumed below. The error occurs with g++ 4.1.1 but not with g++ 4..0.3. Do you see where the error is ?

header file :

//---------------------------------------------
namespace claw
{
namespace graphic
{
class bitmap
{
public:
class reader
{
private:

template<bool Coded4Bits>
class rle_bitmap_output_buffer
{
public:
void fill( unsigned int n, unsigned char pattern );
}; // class rle_bitmap_output_buffer
}; // class reader
}; // class bitmap
} // namespace graphic
} // namespace claw
//----------------------------------------------

implementation (.cpp):

//----------------------------------------------
template<>
void claw::graphic::bitmap::reader::rle_bitmap_output_buffer<false>::fill
( unsigned int n, unsigned char pattern )
{
// some content
}
//----------------------------------------------

The returned error is (in spanish):
error:
especialización de 'void claw::graphic::bitmap::reader::rle_bitmap_output_buffer<Coded4bits>::fill(unsigned
int, unsigned char) [with bool Coded4bits = false]' en un espacio de nombres diferente de la definición de 'void claw::graphic::bitmap::reader::rle_bitmap_output_buffer<Coded4bits>::fill(unsigned
int, unsigned char) [with bool Coded4bits = false]'

If my translation is correct, the compiler tells that the method is specialized in a namespace differing from the one used for its declaration. I can't figure where the problem is.

Thanks

--
Julien Jorge
Doctorant

LINA - Laboratoire d'Informatique de Nantes Atlantique
FRE CNRS 2729
Universite de Nantes
2, rue de la Houssiniere BP 92208
F-44322 Nantes Cedex 03 - FRANCE
Tél : 02.51.12.59.66
 
M

mlimber

Julien said:
Hi,

I have a compilation-time error on the specialization of a method from a imbricated template class, and I can't figure why. The problematic part of the code is resumed below. The error occurs with g++ 4.1.1 but not with g++ 4.0.3. Do you see where the error is ?

header file :

//---------------------------------------------
namespace claw
{
namespace graphic
{
class bitmap
{
public:
class reader
{
private:

template<bool Coded4Bits>
class rle_bitmap_output_buffer
{
public:
void fill( unsigned int n, unsigned char pattern );
}; // class rle_bitmap_output_buffer
}; // class reader
}; // class bitmap
} // namespace graphic
} // namespace claw
//----------------------------------------------

implementation (.cpp):

//----------------------------------------------
template<>
void claw::graphic::bitmap::reader::rle_bitmap_output_buffer<false>::fill
( unsigned int n, unsigned char pattern )
{
// some content
}
//----------------------------------------------

The returned error is (in spanish):
error:
especialización de 'void claw::graphic::bitmap::reader::rle_bitmap_output_buffer<Coded4bits>::fill(unsigned
int, unsigned char) [with bool Coded4bits = false]' en un espacio de nombres diferente de la definición de 'void claw::graphic::bitmap::reader::rle_bitmap_output_buffer<Coded4bits>::fill(unsigned
int, unsigned char) [with bool Coded4bits = false]'

If my translation is correct, the compiler tells that the method is specialized in a namespace differing from the one used for its declaration. I can't figure where the problem is.

It looks like a compiler bug to me (but you should ask in gnu.g++.bug
or gnu.g++.help). Also note that you can't put the a template
implementation in a separate .cpp file without the export keyword,
which I don't think g++ supports (see
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12).

Cheers! --M
 
T

Thomas Tutone

Julien Jorge wrote:

I have a compilation-time error on the specialization of a method from a imbricated template class, and I can't figure why. The problematic part of the code is resumed below. The error occurs with g++ 4.1.1 but not with g++ 4.0.3. Do you see where the error is ?

header file :

//---------------------------------------------
namespace claw
{
namespace graphic
{
class bitmap
{
public:
class reader
{
private:

template<bool Coded4Bits>
class rle_bitmap_output_buffer
{
public:
void fill( unsigned int n, unsigned char pattern );
}; // class rle_bitmap_output_buffer
}; // class reader
}; // class bitmap
} // namespace graphic
} // namespace claw
//----------------------------------------------

implementation (.cpp):

//----------------------------------------------
template<>
void claw::graphic::bitmap::reader::rle_bitmap_output_buffer<false>::fill
( unsigned int n, unsigned char pattern )
{
// some content
}
//----------------------------------------------

The returned error is (in spanish):
error:
especialización de 'void claw::graphic::bitmap::reader::rle_bitmap_output_buffer<Coded4bits>::fill(unsigned
int, unsigned char) [with bool Coded4bits = false]' en un espacio de nombres diferente de la definición de 'void claw::graphic::bitmap::reader::rle_bitmap_output_buffer<Coded4bits>::fill(unsigned
int, unsigned char) [with bool Coded4bits = false]'

If my translation is correct, the compiler tells that the method is specialized in a namespace differing from the one used for its declaration. I can't figure where the problem is.

The compiler is correct. Change your specialization to the following:

namespace claw {
namespace graphic {
template<>
void bitmap::reader::rle_bitmap_output_buffer<false>::fill
( unsigned int n, unsigned char pattern )
{
// some content
}
} // namespace graphic
} // namespace claw

Best regards,

Tom

Tom
 
M

mlimber

Thomas said:
The compiler is correct. Change your specialization to the following:

namespace claw {
namespace graphic {
template<>
void bitmap::reader::rle_bitmap_output_buffer<false>::fill
( unsigned int n, unsigned char pattern )
{
// some content
}
} // namespace graphic
} // namespace claw

Oops. Right. You can also declare a specialization of the whole class
within the namespace and define the function outside it with explicit
qualification:

namespace claw
{
namespace graphic
{
class bitmap
{
public:
class reader
{
public:

template<bool Coded4Bits>
class rle_bitmap_output_buffer
{
private:
void fill( unsigned int, unsigned char );
}; // class rle_bitmap_output_buffer
}; // class reader
}; // class bitmap

template<> class bitmap::reader::rle_bitmap_output_buffer<false>
{
private:
void fill( unsigned int, unsigned char );
};

} // namespace graphic
} // namespace claw

void
claw::graphic::bitmap::reader::rle_bitmap_output_buffer<false>::fill(
unsigned int, unsigned char )
{
// some content
}

Cheers! --M
 
J

Julien Jorge

The solution given by Thomas seems to work well :)

Thank you all.

--
Julien Jorge
Doctorant

LINA - Laboratoire d'Informatique de Nantes Atlantique
FRE CNRS 2729
Universite de Nantes
2, rue de la Houssiniere BP 92208
F-44322 Nantes Cedex 03 - FRANCE
Tél : 02.51.12.59.66
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top