I am having a problem using a vector of a struct I define.
I am trying to add and use this new struct into an existing code base. As such, there is too much code for me to show the actual implementation, but I will try to show a representative approximation.
Inside the header file, I define the struct and try to declare a vector of this type:
class className{
public:
struct newStruct
{
int a;
string b;
double c;
};
protected:
vector < newStruct > vec_of_struct;
However, even this is causing a boat load of compilation errors.
I need not even use this vector in the code, so I know it is not an implementation issue but rather a declaration/instantiation issue. But if I just try to use a variable of the struct's type (i.e. not a vector), it is fine.
I get a mountain of errors when trying to compile, most about seemingly unrelated things elsewhere in the code that in no way interact with this struct. But if I scroll to the top, one example of the error is:
./../../../include/c++/4.7.2/bits/stl_algobase.h: In instantiation of ‘static bool std::__equal<_BoolType>::equal(_II1, _II1, _II2) [with _II1 = const modCSC::ID_Layer_Type*; _II2 = const className::newStruct*; bool _BoolType = false]’:
../../../../include/c++/4.7.2/bits/stl_algobase.h:821:71: required from ‘bool std::__equal_aux(_II1, _II1, _II2) [with _II1 = const className::newStruct*; _II2 = const className::newStruct*]’
which I do not understand.
If I make it a vector of pointers of the struct,
vector < newStruct * > vec_of_struct;
Then the errors go away. However, for my application, I cannot use pointers since the objects I am storing in the vector would otherwise be temporary.
EDIT:
I also get these messages in the compile log:
./../../../include/c++/4.7.2/complex:453:5: note: template argument deduction/substitution failed:
note: ‘const className::newStruct’ is not derived from ‘const std::weibull_distribution<_RealType>’
And similar messages. But there are too many for me to post here.
Yes, sorry, I did not include the 'include' portions of the code, but I do have lines,
#include <vector>
#include <string>
using namespace std;
All in the header file (I did not know this is bad practice)
EDIT 2:
OK, you are right, of course. Scouring for the explicit error message I find:
../../../../include/c++/4.7.2/bits/stl_algobase.h:884:6: error: no match for ‘operator<’ in ‘* __first2 < * __first1’
../../../../include/c++/4.7.2/bits/stl_algobase.h:791:6: error: no match for ‘operator==’ in ‘* __first1 == * __first2’
Aucun commentaire:
Enregistrer un commentaire