using two operators in same line

Discussion in 'C++' started by ankitks@yahoo.com, Oct 20, 2006.

  1. Guest

    Hello programmers,
    I am trying to write a class which has a two operators # and <=, so
    that I can do something like this.
    ...
    Array mArray;
    .....
    #4 mArray <= 5; //is this possible to have for # operator to have
    nothing on LHS, I can get <= operator work, mArray <=5, but can't think
    of anyway to combined both operator togeather! can return refrence to
    Array in <= operator to do something like (4# mArray <= 5) to work.

    Idealy I like to have #4 mArray <= 5;
    but I can live with some other versions, 4# mArray <= 5 or (mArray <=
    5) #4 (really not prefer this!)

    Any suggestions, comments, help?

    class defination for Array
    class Array
    {
    public:
    Array();
    ~Array():
    operator<= (const int inIndex) {mIndex = inIndex;}
    friend ?? operotor# (const Array& in Array)
    private:
    int mIndex;
    };
     
    , Oct 20, 2006
    #1
    1. Advertising

  2. red floyd Guest

    wrote:
    > Hello programmers,
    > I am trying to write a class which has a two operators # and <=, so
    > that I can do something like this.
    > ..
    > Array mArray;
    > ....
    > #4 mArray <= 5; //is this possible to have for # operator to have
    > nothing on LHS, I can get <= operator work, mArray <=5, but can't think
    > of anyway to combined both operator togeather! can return refrence to
    > Array in <= operator to do something like (4# mArray <= 5) to work.
    >
    > Idealy I like to have #4 mArray <= 5;
    > but I can live with some other versions, 4# mArray <= 5 or (mArray <=
    > 5) #4 (really not prefer this!)
    >
    > Any suggestions, comments, help?
    >
    > class defination for Array
    > class Array
    > {
    > public:
    > Array();
    > ~Array():
    > operator<= (const int inIndex) {mIndex = inIndex;}
    > friend ?? operotor# (const Array& in Array)
    > private:
    > int mIndex;
    > };
    >



    First of all, you *can't* define operator#. There is no such operator.
    Given that, you're toast anyways.
     
    red floyd, Oct 20, 2006
    #2
    1. Advertising

  3. Guest

    sorry, also forgot one more important point,
    how can I have a higher precedence set for <= operator. Assignments
    should always evaluate <= first and after that #)

    thanks

    wrote:
    > Hello programmers,
    > I am trying to write a class which has a two operators # and <=, so
    > that I can do something like this.
    > ..
    > Array mArray;
    > ....
    > #4 mArray <= 5; //is this possible to have for # operator to have
    > nothing on LHS, I can get <= operator work, mArray <=5, but can't think
    > of anyway to combined both operator togeather! can return refrence to
    > Array in <= operator to do something like (4# mArray <= 5) to work.
    >
    > Idealy I like to have #4 mArray <= 5;
    > but I can live with some other versions, 4# mArray <= 5 or (mArray <=
    > 5) #4 (really not prefer this!)
    >
    > Any suggestions, comments, help?
    >
    > class defination for Array
    > class Array
    > {
    > public:
    > Array();
    > ~Array():
    > operator<= (const int inIndex) {mIndex = inIndex;}
    > friend ?? operotor# (const Array& in Array)
    > private:
    > int mIndex;
    > };
     
    , Oct 20, 2006
    #3
  4. Guest

    thanks, good to know, how about using then ^ or @
    red floyd wrote:
    > wrote:
    > > Hello programmers,
    > > I am trying to write a class which has a two operators # and <=, so
    > > that I can do something like this.
    > > ..
    > > Array mArray;
    > > ....
    > > #4 mArray <= 5; //is this possible to have for # operator to have
    > > nothing on LHS, I can get <= operator work, mArray <=5, but can't think
    > > of anyway to combined both operator togeather! can return refrence to
    > > Array in <= operator to do something like (4# mArray <= 5) to work.
    > >
    > > Idealy I like to have #4 mArray <= 5;
    > > but I can live with some other versions, 4# mArray <= 5 or (mArray <=
    > > 5) #4 (really not prefer this!)
    > >
    > > Any suggestions, comments, help?
    > >
    > > class defination for Array
    > > class Array
    > > {
    > > public:
    > > Array();
    > > ~Array():
    > > operator<= (const int inIndex) {mIndex = inIndex;}
    > > friend ?? operotor# (const Array& in Array)
    > > private:
    > > int mIndex;
    > > };
    > >

    >
    >
    > First of all, you *can't* define operator#. There is no such operator.
    > Given that, you're toast anyways.
     
    , Oct 20, 2006
    #4
  5. Puppet_Sock Guest

    wrote:
    > red floyd wrote:
    > > wrote:
    > > > I am trying to write a class which has a two operators # and <=, so


    [snips, and top posting corrected]

    > > First of all, you *can't* define operator#. There is no such operator.
    > > Given that, you're toast anyways.

    > thanks, good to know, how about using then ^ or @


    Well, what would operator # do if it did exist? What are you
    trying to get from it?

    Um. I don't think there's an operator @, is there?
    Socks
     
    Puppet_Sock, Oct 20, 2006
    #5
  6. Ron Natalie Guest

    Puppet_Sock wrote:

    > Um. I don't think there's an operator @, is there?
    > Socks
    >

    @ and $ do not exist in the C++ syntax anywhere
    (outside of char/string literals).
     
    Ron Natalie, Oct 20, 2006
    #6
  7. Guest

    if operator # exit, I like to do something

    operator# (const int inCount) {mIndex = mIndex * inCount;}

    this is just example.



    Puppet_Sock wrote:
    > wrote:
    > > red floyd wrote:
    > > > wrote:
    > > > > I am trying to write a class which has a two operators # and <=, so

    >
    > [snips, and top posting corrected]
    >
    > > > First of all, you *can't* define operator#. There is no such operator.
    > > > Given that, you're toast anyways.

    > > thanks, good to know, how about using then ^ or @

    >
    > Well, what would operator # do if it did exist? What are you
    > trying to get from it?
    >
    > Um. I don't think there's an operator @, is there?
    > Socks
     
    , Oct 20, 2006
    #7
  8. schrieb:
    > Hello programmers,
    > I am trying to write a class which has a two operators # and <=, so
    > that I can do something like this.
    > ..
    > Array mArray;
    > ....
    > #4 mArray <= 5; //is this possible to have for # operator to have
    > nothing on LHS, I can get <= operator work, mArray <=5, but can't think
    > of anyway to combined both operator togeather! can return refrence to
    > Array in <= operator to do something like (4# mArray <= 5) to work.

    [...]

    There is no # operator, and I doubt that your <= operator is an "lesser
    equal" operator. Don't confuse other compilers by changing the meaning of
    operators.

    Read the FAQ on operator overloading:
    http://www.parashift.com/c -faq-lite/operator-overloading.html

    --
    Thomas
    http://www.netmeister.org/news/learn2quote.html
     
    Thomas J. Gritzan, Oct 20, 2006
    #8
  9. Marcus Kwok Guest

    wrote:
    > sorry, also forgot one more important point,
    > how can I have a higher precedence set for <= operator. Assignments
    > should always evaluate <= first and after that #)


    You can not change the precedence (or associativity) of operators. This
    is why it is not recommened to overload operator^ to do exponentiation,
    for example; see:
    http://www.parashift.com/c -faq-lite/operator-overloading.html#faq-13.7

    --
    Marcus Kwok
    Replace 'invalid' with 'net' to reply
     
    Marcus Kwok, Oct 20, 2006
    #9
  10. Rolf Magnus Guest

    wrote:

    > if operator # exit, I like to do something
    >
    > operator# (const int inCount) {mIndex = mIndex * inCount;}
    >
    > this is just example.


    Operator overloading is for doing things with your own types that are
    logically similar to what the same operator would do with built-in types.
    It is supposed to help you extend the langage, not change it into a
    different one. Since there is no operator# for built-in types, there is
    nothing useful it could do and so you can't define your own either.
    You can overload operator^, but only as a binary operator (i.e. having two
    arguments, one on the left and one on the right side). It's supposed to do
    a bitwise exclusive or of the two arguments.
     
    Rolf Magnus, Oct 20, 2006
    #10
  11. Daniel T. Guest

    In article <>,
    wrote:

    > Hello programmers,
    > I am trying to write a class which has a two operators # and <=, so
    > that I can do something like this.


    You cannot invent operators, all you can do is implement the operators
    that already exist.

    --
    There are two things that simply cannot be doubted, logic and perception.
    Doubt those, and you no longer have anyone to discuss your doubts with,
    nor any ability to discuss them.
     
    Daniel T., Oct 20, 2006
    #11
    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. Replies:
    12
    Views:
    2,817
    Slartibartfast
    Sep 23, 2003
  2. raju
    Replies:
    49
    Views:
    1,967
    Jordan Abel
    Nov 7, 2005
  3. Kufa
    Replies:
    11
    Views:
    554
    Ivan Novick
    Jan 18, 2007
  4. Shiloh Madsen
    Replies:
    5
    Views:
    121
    Morton Goldberg
    Nov 21, 2006
  5. Avnesh Shakya
    Replies:
    6
    Views:
    184
    Grant Edwards
    May 28, 2013
Loading...

Share This Page