!= Overloading

This is a discussion on != Overloading within the C++ Programming forums, part of the General Programming Boards category; Hi, I am trying to overload the != in my method. I am not getting any errors in my program, ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    4

    != Overloading

    Hi,
    I am trying to overload the != in my method. I am not getting any errors in my program, but my output is just not coming up. Basically, I just want my cout to work and I really don't care about != in my coming up with anything but true right now, cause I know i can alter it later. Thanks for any help anyone can offer me.
    Here is my code:
    Code:
    //in my main:
    	if (test != test2) cout << "They are equal" << endl;
    	else cout << "They are not equal" << endl;
    
    //in my header:
    bool operator!=( const StringList &right ) const;
    
    //in my class
    bool StringList::operator!=(const StringList& s2) const{
    	return true;
    }
    Basically, the words They are equal and They are not equal are not showing up, even though They are equal should always appear as the != always returns true.
    Thanks again for any help anyone could offer me.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    Something else is going wrong. That is an if/else, so one of the two output messages should always appear. Can you post more context to the main code.

    Your operator!= declaration and implementation look fine.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Overloading operators
    By ugmusicbiz in forum C++ Programming
    Replies: 2
    Last Post: 02-13-2009, 12:41 PM
  2. unary operator overloading and classes
    By coletek in forum C++ Programming
    Replies: 9
    Last Post: 01-10-2009, 01:14 AM
  3. overloading operator problems
    By almich in forum C++ Programming
    Replies: 2
    Last Post: 07-26-2004, 04:10 PM
  4. operator overloading
    By blue_gene in forum C++ Programming
    Replies: 6
    Last Post: 04-29-2004, 04:06 PM
  5. overloading
    By theLukerBoy in forum C++ Programming
    Replies: 6
    Last Post: 11-04-2002, 07:49 PM

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