Is it legal to create such a member template conversion operator?

Discussion in 'C++' started by unkstar@163.com, Dec 24, 2007.

  1. Guest

    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?
    , Dec 24, 2007
    #1
    1. Advertising

  2. red floyd Guest

    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.
    red floyd, Dec 24, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ghager
    Replies:
    6
    Views:
    621
    ghager
    Jan 19, 2006
  2. nutty
    Replies:
    4
    Views:
    392
    nutty
    Jun 11, 2006
  3. Ingo
    Replies:
    2
    Views:
    565
  4. Hicham Mouline
    Replies:
    0
    Views:
    432
    Hicham Mouline
    Apr 23, 2009
  5. Hicham Mouline
    Replies:
    1
    Views:
    414
    Michael DOUBEZ
    Apr 24, 2009
Loading...

Share This Page