Hello,
i have a struct vector and a struct variable (without identifier).
I want to delete this struct variable from my struct vector.
This would be a example:
How do i set the == Operator when it is a typedef struct instead of a struct?
1 2 3 4 5
typedefstruct
{
DWORD i;
DWORD b;
} MyStruct;
Besides, if i would change all "typedef structs" to "structs", would that be also a improvement of the code? (is it advised to use struct instead of typedef struct to the todays time)
Besides #2:
I dont even get the snippet of ajh32 compiled, it says, that the remove funktion dont accept 3 arguments.
Add #2:
Did need to add:
#include <algorithm>
Besides, if i would change all "typedef structs" to "structs", would that be also a improvement of the code? (is it advised to use struct instead of typedef struct to the todays time)
In C++, it isn't necessary to use the typedef. That's a C anachronism.
@tcs - it's because the operator== is a binary operator whereas in the above struct I have declared two arguments to the operator==, under this scenario we need to declare the operator== as a friend because there is no '*this' outside the class instance. We need the operator== to have two operands otherwise it wouldn't play with the std::remove function that will pass two MyStructs through (in this example).
@cire - well no not when it is external to the struct. I think it's cleaner to have the operator within the struct/class to which it refers to. But hey ho...
That seems a little disingenuous to me. It is external to the struct either way it is defined, and it is cleaner, IMO, for stuff which is external to the struct to be defined outside of the struct. It becomes even less attractive when the data is private and the operator can be implemented by using only the public interface.