Data in both structs has been stored in vectors. Both structs also contain vectors inside it. I want to match each element of the vector [code]LC0413_IDs[/code] (of struct LC_block) with id1 and id2 (of struct TRS_block) for equality. If any of the elements of vector LC0413_IDs matches either of the two ids i-e id1 and id2, then e-g a flag would be set to true.
if you have vector<LC_block> LC_array; and just one element TRS_block TRS_var you could check like this (where i is declared beforehand and within LC_array... and j is declared and withing LC0413_IDs)
1 2 3 4 5
if ( LC_array[i].LC0413_IDs[j].compare(TRS_var.id1) == 0 ||
LC_array[i].LC0413_IDs[j].compare(TRS_var.id2) == 0 )
{
//.. set the flag
}
wolfgang I have done exactly the way Duoas suggested. I searched for the error on google and found that When overloading the == operator, define it as an external function, not as a member function, and declare that extern function a friend of the relevant class or struct. It removed the error. But now it gives me some other errors.
[code removed]
ERRORS:
[code removed]
is it because the code is trying to compare a variable with a whole vector? Sorry for being silly as I dont know about the syntax. I want to compare each element of the vectors [code]LC_block::LC0413_IDs[/code] and LC_block::LC0419_IDs with TRS_block::id1 and TRS_block::id2. If any of the elements of both these vectors equals any of the IDs then a flag should be set to true.
Thank you so much jsmith but I am still confused about the syntax ;'(
The vector that has struct TRS_block data is trs_file_as_blocks and the vector that has struct LC_block data is lc_file_as_blocks. How am I going to check if any of the elements of the two vectors of type struct LC_block is equal to either id1 or id2 of struct TRS_block. Could you please write to me the lines of code.
Let me understand. You have an instance of TRS_block and an instance of LC_block.
You want to check if id1 or id2 is present in either vector instead LC_block?
The line I gave you above, which you would put in your first operator== (lines 3 and 4)
checks if id1 is in one of the vectors. You have to write three more similar checks for
the other three permutations. (check if id1 is in the other vector, check if id2 is in the
first vector, check if id2 is in the second vector).
You have an instance of TRS_block and an instance of LC_block. You want to check if id1 or id2 is present in either vector instead LC_block?
where those two vectors are declared inside the struct LC_block
The line I gave you above, which you would put in your first operator== (lines 3 and 4) checks if id1 is in one of the vectors.
I want to check if vector-1 of struct LC_block has an element equal to id1 of struct TRS_block or an element equal to id2 of struct TRS_block, similary check to see if vector-2 of struct LC_block has an element equal to id1 of struct TRS_block or an element equal to id2 of struct TRS_block.
[code removed]
That's the way I have done it without using the overloaded == operator and it is working fine but could you please modify the code for me according to the overloaded == operator?
Your first block of code does what you say you want it to do.
Your second block of code now says I have a vector of TRS_blocks and a vector of
LC_blocks, and I want to see if any element of the TRS_block vector is equal to
any element of the LC_block vector according to the rules set forth in the first
code block.
Your second block is basically what you need to do, though lines 5-8 are nothing
more than operator== which std::find will call:
I want to see if any element of the TRS_block vector is equal to any element of the LC_block vector according to the rules set forth in the first code block.
No I want to check if [code]id1 OR id2 of the struct TRS_block[/code] is equal to any element of the two string type vectors contained in the struct LC_block
[code removed]
Your code:
[code removed]
Should it not be something like [code]trs.id1 OR trs.id2[/code] and lc.LC0413_IDs AND lc.LC0419_IDs and friendbooloperator == ( const TRS_block& trs, const LC_block& lc ).
The second one calls the first one indirectly via the std::find(). They should not be declared friends.
The second one returns true if any of the following conditions are true:
1) If any id1 in any TRS_block (trs) matches any element of LC0413_IDs in any LC_block (lc);
2) If any id1 in any TRS_block (trs) matches any element of LC0419_IDs in any LC_block (lc);
3) If any id2 in any TRS_block (trs) matches any element of LC0413_IDs in any LC_block (lc);
4) If any id2 in any TRS_block (trs) matches any element of LC0419_IDs in any LC_block (lc);
Thank you so much jsmith but I can't seem to figure out the problem as it still is giving me an error ;'( . I think I should leave it like this for the moment as it is working and should show it the way it is. However, there is one other issue in this program. Could you please read my next thread and see if you could help me with that.