473,396 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Can't figure out specialziation syntax for g++.

Heya -

The following works with MSVC:

template< bool Boolean >
struct Foo
{
template< class T2 >
void bar( T2 arg )
{
std::cout << arg << std::endl;
}

template<>
void bar( bool arg )
{
if ( Boolean )
std::cout << arg << std::endl;
}

};

Of course, g++ complains about "explicit specialization in non-namespace
scope" - this is usually no big deal, just move the specialization
outside of th class, right? For this example, I'm unable to figure out
how to move the specialization outside of the class definition without
generating a raft of errors, with either compiler. Basically I think
this is some type of partial specialization, but the wrench is the
'bool' as the template parameter of the class.

The closest I've been able to come up with is:

template<>
template< bool Boolean >
inline void Foo<bool>::bar( bool arg )
{
}

but it doesn't seem to work.

Any help would be greatly appreciated. :)

- John

Nov 30 '06 #1
2 1130
"John" <jo**@x.yywrote in message
news:py******************@tornado.texas.rr.com
Heya -

The following works with MSVC:

template< bool Boolean >
struct Foo
{
template< class T2 >
void bar( T2 arg )
{
std::cout << arg << std::endl;
}

template<>
void bar( bool arg )
{
if ( Boolean )
std::cout << arg << std::endl;
}

};

Of course, g++ complains about "explicit specialization in
non-namespace scope" - this is usually no big deal, just move the
specialization outside of th class, right? For this example, I'm
unable to figure out how to move the specialization outside of the
class definition without generating a raft of errors, with either
compiler. Basically I think this is some type of partial
specialization, but the wrench is the 'bool' as the template
parameter of the class.
The closest I've been able to come up with is:

template<>
template< bool Boolean >
inline void Foo<bool>::bar( bool arg )
{
}

but it doesn't seem to work.

Any help would be greatly appreciated. :)

What you are trying to do is not allowed by the standard, though VC++ does
allow it for backward compatibility reasons.

According to the standard, you are only allowed to specialise member
templates if the enclosing template class is fully specialised. Something
like this:

template< bool Boolean >
struct Foo
{
template< class T2 >
void bar( T2 arg )
{
std::cout << arg << std::endl;
}
};

template<>
template<>
void Foo<true>::bar<bool>( bool arg )
{
// Foo<truecase
}

template<>
template<>
void Foo<false>::bar<bool>( bool arg )
{
// Foo<falsecase
}
--
John Carson

Nov 30 '06 #2
John Carson wrote:
"John" <jo**@x.yywrote in message
news:py******************@tornado.texas.rr.com
>Heya -
According to the standard, you are only allowed to specialise member
templates if the enclosing template class is fully specialised. Something
like this:
Awsome! I can deal with that.

Thanks!

Nov 30 '06 #3

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

Similar topics

5
by: BStorm | last post by:
I have a transaction log file where the DataSet table's Description column is actually delimited into "subcolumns" based upon the transaction id. I would like to parse these into separate fields...
4
by: Aaron Walker | last post by:
Greetings, I'm attempting to write my first *real* template function that also deals with a map of strings to member function pointers that is making the syntax a little tricky to get right. ...
6
by: Frankie Montenegro | last post by:
Hi everyone, I need some help with the following C++ code. It is supposed to read input line by line, each line as one string; then split each string into its component words and store these...
2
by: Wayne Wengert | last post by:
I am trying to code a Sub to store some custom values in a profile for a new user registration (ASP.NET 2.0 environment). I copied the basic code from an example I found in a great article...
3
by: Brian Blais | last post by:
Hello, I have an odd kind of Heisenbug in what looks like a pretty simple program. The program is a progress bar code I got at the Python Cookbook: ...
52
by: Jim Langston | last post by:
I wanted to do an operator override for but couldnt' figure out the syntax. I tried this (code that doesn't compile commented out with //: class CMyBitmap { public: CMyBitmap( int Rows, int...
4
by: _Raven | last post by:
Okay, I am playing with submitting forms with Ajax. I am trying to adapt this script to my forms: http://www.captain.at/howto-ajax-form-post-get.php I have included my code at the bottom of this...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
4
by: Chris Allen | last post by:
I am confused on one aspect of exception handling. If you specify the exception object type to match in an except statement it is possible to also obtain the exception object itself, but I can't...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
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...

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.