operator problemz w/namespace

This is a discussion on operator problemz w/namespace within the C++ Programming forums, part of the General Programming Boards category; namespace ops { fop_base_class operator , (int s,int u) { printf("%i , %i",s,u); } }; It gives me this error: ...

  1. #1
    Registered User minime6696's Avatar
    Join Date
    Aug 2001
    Posts
    267

    Exclamation operator problemz w/namespace

    namespace ops
    {
    fop_base_class operator , (int s,int u)
    {
    printf("%i , %i",s,u);
    }
    };

    It gives me this error:
    (im using MSVC)

    D:\programming dump\fop.cpp(5) : error C2803: 'operator ,' must have at least one formal parameter of class type

    Can someone help... ive tried a lot of things... cant figure it out!

    SPH

  2. #2
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    You can't overload operators for built in types.

  3. #3
    Registered User minime6696's Avatar
    Join Date
    Aug 2001
    Posts
    267

    Question ?

    What does that mean? Can't overloadglobal operators?

    SPH

  4. #4
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    No it's nothing to do with whether the variables or operator function is global. You can only overload operators for types you create yourself (with classes), you can't overload for int's alone otherwise the compiler doesn't know whether to use your overloaded operator or the built in one.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21