|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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. |
|
![]() |
| Outils de la discussion | |
|
|