Templatized operator () overload

Discussion in 'C++' started by Paul Escherton, Nov 10, 2003.

  1. I'm trying to templatize the operator(), but VisualStudio .NET 2003 I
    get an odd error. I'm wondering if there is a way to do this and what
    the proper syntax is. If there is not, why not?

    My code looks like:

    class DaClass
    {
    public:
    template <class T> T operator( ) ( )
    {
    return T;
    }
    };

    and I attempt to call the operator like this:
    DaClass daClass;
    daClass<bool>( );
    daClass<bool>operator( );

    I get an error on both the lines where I try to call the operator of:
    'type 'bool' unexpected'.

    Any thoughts? Thanks in advance.
     
    Paul Escherton, Nov 10, 2003
    #1
    1. Advertising

  2. Paul Escherton

    Dave Guest

    "Paul Escherton" <> wrote in message
    news:3faf20f7$0$200$...
    > I'm trying to templatize the operator(), but VisualStudio .NET 2003 I
    > get an odd error. I'm wondering if there is a way to do this and what
    > the proper syntax is. If there is not, why not?
    >
    > My code looks like:
    >
    > class DaClass
    > {
    > public:
    > template <class T> T operator( ) ( )
    > {
    > return T;
    > }
    > };
    >
    > and I attempt to call the operator like this:
    > DaClass daClass;
    > daClass<bool>( );
    > daClass<bool>operator( );
    >
    > I get an error on both the lines where I try to call the operator of:
    > 'type 'bool' unexpected'.
    >
    > Any thoughts? Thanks in advance.
    >


    Your trying to return a type? ("return T;") Can't do dat! You need to
    return a value of the type!
     
    Dave, Nov 10, 2003
    #2
    1. Advertising

  3. Paul Escherton

    tom_usenet Guest

    On Sun, 09 Nov 2003 22:24:17 -0700, Paul Escherton
    <> wrote:

    >I'm trying to templatize the operator(), but VisualStudio .NET 2003 I
    >get an odd error. I'm wondering if there is a way to do this and what
    >the proper syntax is. If there is not, why not?
    >
    >My code looks like:
    >
    >class DaClass
    >{
    >public:
    > template <class T> T operator( ) ( )
    > {
    > return T;
    > }
    >};
    >
    >and I attempt to call the operator like this:
    >DaClass daClass;
    >daClass<bool>( );
    >daClass<bool>operator( );


    The above syntax is wrong. How about:

    daClass.operator()<bool>();

    But why do you want to template operator() it only on the return type?
    I can't think of any use for that, since you can't call the function
    without explicit template parameters.

    Tom
     
    tom_usenet, Nov 10, 2003
    #3
    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. mrstephengross
    Replies:
    5
    Views:
    604
    Larry I Smith
    May 18, 2005
  2. StephQ
    Replies:
    1
    Views:
    325
  3. kausikd
    Replies:
    0
    Views:
    241
    kausikd
    Aug 6, 2010
  4. kcsasquatch
    Replies:
    2
    Views:
    573
    Johannes Schaub (litb)
    Aug 31, 2010
  5. Ying-Chieh Liao

    function overload (not operator overload)

    Ying-Chieh Liao, Oct 11, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    255
    Sherm Pendley
    Oct 11, 2004
Loading...

Share This Page