Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Is it legal to create such a member template conversion operator? (http://www.velocityreviews.com/forums/t563512-is-it-legal-to-create-such-a-member-template-conversion-operator.html)

unkstar@163.com 12-24-2007 05:09 PM

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?

red floyd 12-24-2007 10:45 PM

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.




All times are GMT. The time now is 04:06 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.