473,473 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Specialization of a method from an imbricated template class

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_b uffer<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_b uffer<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_b uffer<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
Oct 30 '06 #1
4 1556
Julien Jorge wrote:
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_b uffer<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_b uffer<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_b uffer<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-lit...tml#faq-35.12).

Cheers! --M

Oct 30 '06 #2
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_b uffer<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_b uffer<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_b uffer<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>::f ill
( unsigned int n, unsigned char pattern )
{
// some content
}
} // namespace graphic
} // namespace claw

Best regards,

Tom

Tom

Oct 30 '06 #3
Thomas Tutone wrote:
The compiler is correct. Change your specialization to the following:

namespace claw {
namespace graphic {
template<>
void bitmap::reader::rle_bitmap_output_buffer<false>::f ill
( 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_b uffer<false>::fill(
unsigned int, unsigned char )
{
// some content
}

Cheers! --M

Oct 30 '06 #4
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
Oct 31 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: SainTiss | last post by:
Hi, If you've got a template class with lots of methods, and then you've got a type which works with the template, except for one method... What you need to do there is specialize the...
8
by: Agent Mulder | last post by:
Hi group, I have a problem with partial template specialization. In the code below I have a template struct Music with one method, play(), and three kinds of music, Jazz, Funk and Bach. When I...
0
by: Gonçalo Rodrigues | last post by:
Hi all, I'm working around with smart pointers mostly as a learning exercise: I have a single-rooted hierarchy with the root class Object. Every Object has a member field count, the number of...
5
by: __PPS__ | last post by:
Hello, I want to write specialized method for a class: template<class A, class B> class xxx{ A a; B b; operator bool()const{ a==b; } };
5
by: pmatos | last post by:
Hi all, I have implemented a matrix template to suit my needs and now I've implemented some methods for computing SVD decomposition of Matrix<double>. I have: template <class T> class Matrix...
1
by: Michael Stembera | last post by:
I have a case of a very simple template class w/ a template method. If I define a specialization of the method outside the body of the template class it does not compile. Here is a tiny example...
2
by: Yang Zhang | last post by:
I have a small program like this: //////////////////////////////////////////////// #include <iostream> using namespace std ; // set bits in an address template <typename T> inline T*...
2
by: Barry | last post by:
The following code compiles with VC8 but fails to compiles with Comeau online, I locate the standard here: An explicit specialization of any of the following:
7
by: (2b|!2b)==? | last post by:
I have a class template. Each of the instantiations implements a method in the class template differently, so I (need?) to use template speciaization. My question is this, when writing the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.