CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2009
    Posts
    1,689

    Way to have certain fields ignored in compare

    I have two fields that are equal to each other, except for one field. Is there a way to get the comparison to ignore that field? It's an iterator pointer, the iterator position should not matter when comparing objects to each other.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Way to have certain fields ignored in compare

    I'm sorry, can you be more specific? Some code to help us understand what you are doing?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Way to have certain fields ignored in compare

    Code:
    class foo {
    	   private $_mapping = array(1,2,3);
    	   private $_position = 0;
    	   public function rewind() { 
    		  $this -> _position = 0;
    	   }
    	   public function current() {
    		  return $this -> _mapping[$this -> _position];
    	   }
    	   public function key() {
    		  return $this -> _position;
    	   }
    	   public function next() {
    		  ++$this -> _position;
    	   }
    	   public function valid() { 
    		  return isset($this -> _mapping[$this -> _position]);
    	   }
    }
    
    $test = new foo();
    $test2 = new foo()
    foreach($test as $i){}
    echo '' . $test == $test2;   //false because _position is in different places, but the actual content in the same

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Way to have certain fields ignored in compare

    I'm sorry but without any explanation, this still isn't helping. Let me try to explain what isn't exactly understandable...

    Quote Originally Posted by ninja9578
    I have two fields that are equal to each other, except for one field.
    • Two equal minus one results in none equal. So what exactly are you comparing?
    • What do you mean by field? Are these <input> values passed to the server?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Way to have certain fields ignored in compare

    The mapping members are exactly the same, the _position item is different, but does not affect the "value" of the object publicly. I want the $test == $test2 to be true.

    I want it be be the equivalent of this

    Code:
    bool operator == (const foo & $bar){
       return $bar -> _mapping == $this -> _mapping;
    }
    Last edited by ninja9578; October 27th, 2010 at 02:24 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured