PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Is it legal to create such a member template conversion operator?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Is it legal to create such a member template conversion operator?

Réponse
 
LinkBack Outils de la discussion
Vieux 24/12/2007, 17h09   #1
unkstar@163.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Is it legal to create such a member template conversion operator?

I've written a extentable_buffer class, which allows me to acquire
bigger buffer whenever I need. The original version has a conversion
operator to void*, it's enought for that good old time. things changed
later, its used anywhere necessary in the code. and soon, I was bored
up by chained (type*)(void*) conversion. so, I deciede to write a
generic conversion operator, sth like this:

class extentable_buffer
{
public:
template<typename _Ty>
operator _Ty*()
{
return (_Ty*)myBuf;
}
//...ohter member function here
private:
void *myBuf;
};

Here comes the nightmare, our company is still using MSVC6.0 and gcc
2.7.4. the former one give dozens of error message, well, msvc6
dosen't event support partial-specialization, let's ignore it first.
When I attempt to compile this thing with gcc, it suprised me by such
an message:"internal compiler error, please contact us with full error
report. "OMFG..

I've looked up TC++PL for answer, but find nothing exactly about this,
no for, nor against.

what's worst, when I get home, and try these code with my msvc8, it
just works perfect as I expected! this confused me.
what happen? is such a member template conversion operator legal or
not? where can I find the related description in TC++PL?
  Réponse avec citation
Vieux 24/12/2007, 22h45   #2
red floyd
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is it legal to create such a member template conversion operator?

unkstar@163.com wrote:
> I've written a extentable_buffer class, which allows me to acquire
> bigger buffer whenever I need. The original version has a conversion
> operator to void*, it's enought for that good old time. things changed
> later, its used anywhere necessary in the code. and soon, I was bored
> up by chained (type*)(void*) conversion. so, I deciede to write a
> generic conversion operator, sth like this:
>
> class extentable_buffer
> {
> public:
> template<typename _Ty>
> operator _Ty*()
> {
> return (_Ty*)myBuf;
> }
> //...ohter member function here
> private:
> void *myBuf;
> };
>
> Here comes the nightmare, our company is still using MSVC6.0 and gcc
> 2.7.4. the former one give dozens of error message, well, msvc6
> dosen't event support partial-specialization, let's ignore it first.
> When I attempt to compile this thing with gcc, it suprised me by such
> an message:"internal compiler error, please contact us with full error
> report. "OMFG..



VC6 and gcc 2.7.4 are incredibly ancient, pre-Standard compilers. Don't
bother using them as a reference. Gcc is at 4.something and VC is at
version 2008 (3 versions post-VC6).

For what it's worth, Comeau online compiles it in strict C++03 mode.

However, your choice of template parameter name is invalid. Any
identifier with a leading underscore followed by an upper-case
letter (such as _Ty -- hint hint) is reserved to the implementation.
As such, *YOU MAY NOT USE IT FOR YOUR OWN PURPOSES*. If you used
"T" instead of "_Ty", you'd have perfectly legal code.


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 10h55.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09672 seconds with 10 queries