GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 16-Jun-2004, 04:15
Nelly Nelly is offline
New Member
 
Join Date: Apr 2004
Posts: 15
Nelly is on a distinguished road

Comparing two arrays


Hello guys,
I am using Visual C++ 6.0.

I have a vector of array. Each element of the vector contains an array [25].
I have a button on my dialog window which call a save function to to save the array in the vector.
I want to add a function to check the changes made to the array and pop up a message if the user forget to save changes.

I want save a copy of the array at the start and use that array to check for any changes made. That is, compare the copy and the main array.


Code:
bool savechanges() { //making a copy of the vector for (int i = 0; i < Feat.size(); i++) { FaceCopy = Feat[i]; } //call the function to add update the vector element, ie, the array addFeatures(); for (int j = 0; j < CFF.Feat.size(); j++) { FaceFeat = Feat[j]; } // ckecking using the FrameNo ans index if (Feat[j].FrameNo = Feat[i].FrameNo) { //if there is no change don't call the pop dialog if (FaceCopy == FaceFeat) { return false; } else //call the Save popup dialog to save the changes if (FaceCopy != FaceFeat) { /**Call the Apply pop-up dialog box the allow users to save changes to the vector*/ CSaveDlg Sav; if(Sav.DoModal()== IDOK) { /**Save array to the vector*/ OnSave(); } } } return true; }

But unfortunately I get the following error messages:

error C2678: binary '==' : no operator defined which takes a left-hand operand of type 'struct Face' (or there is no acceptable conversion)

error C2678: binary '!=' : no operator defined which takes a left-hand operand of type 'struct Face' (or there is no acceptable conversion)

I have included the following header

Code:
#include <iostream> using namesapae std; #include <vector> #include <algorithm> #include <math> #include <cstring>

Can anyone please advise on what I'm doing wrong.

Thank you very in advance...
  #2  
Old 16-Jun-2004, 05:15
sho sho is offline
Junior Member
 
Join Date: Jun 2004
Posts: 49
sho will become famous soon enough
Well, i think your problem is here:
if (FaceCopy == FaceFeat)
and if (FaceCopy != FaceFeat)
specifically in the comparations "FaceCopy == FaceFeat", "FaceCopy != FaceFeat"...

Its because you cant compare two different arrays or structures like that, you would have to do comparison comparind their elements one by one...

The "==" operator doesnt accepts structures or arrays because they may contain many elements and it only compares between pairs of simple elements... so thats why the compiler says:

error C2678: binary '==' : no operator defined which takes a left-hand operand of type 'struct Face' (or there is no acceptable conversion)

error C2678: binary '!=' : no operator defined which takes a left-hand operand of type 'struct Face' (or there is no acceptable conversion)
  #3  
Old 16-Jun-2004, 05:38
Garth Farley Garth Farley is offline
Invalid Email Address
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
You're not making copies or comparing them properly. Your copy loop:
CPP / C++ / C Code:
 //making a copy of the vector
for (int i  = 0; i < Feat.size(); i++)
{
    FaceCopy   = Feat[i];
}
is flawed. All this is doing is:
FaceCopy = Feat[0];
FaceCopy = Feat[1];
FaceCopy = Feat[2];
FaceCopy = Feat[3];
...
i.e. it's overwriting whatever value is placed in FaceCopy. So all it ends up with the last value in the object Feat.

Similarily for the second loop. Also then after, are you sure you wish to use the iterative indices i & j outside the scope of their loops?

Whatever types FaceCopy & FaceFeat are, there is no comparison operators defined. Are they objects? If so you can create them as follows (C++ only):
CPP / C++ / C Code:
bool Feat::operator==(const Feat&, const Feat&){
      if( identical - check each element of the array) return true;
      else return false;
}
If you're sticking to C and structs, you'll have to loop through each member of the struct explicitly.
GF
 
 

Recent GIDBlogStupid Management Policies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
problems with 2d arrays.. mgdpetter C Programming Language 12 27-May-2004 21:45
need help with passing 3 arrays into a function tommy69 C Programming Language 14 07-Apr-2004 01:22
help on comparing structs nusstu C Programming Language 4 03-Apr-2004 03:22
Problem multiplying arrays hellhammer C Programming Language 9 29-Mar-2004 16:32
pointers and arrays jack C Programming Language 4 15-Jan-2004 13:27

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:37.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.