I'm still new to C , and I have to create an online store by defining a few classes. But the thing is, even after having gotten rid of all the errors in my files, Visual Studio shows me an error in an xutility file : Error C3889 call to a class object « std::equal_to » : corresponding call operator not found. I don't really know what this file is, but after a few researches I simply found out that there might be an error if one of my functions/classes has the same name as one from this file. Also, here is the part of the code where the error occurs ( last for loop, on _Pred ) :
template <class _InIt1, class _InIt2, class _Pr> _NODISCARD _CONSTEXPR20 bool equal(const _InIt1 _First1, const _InIt1 _Last1, const _InIt2 _First2, _Pr _Pred) { compare [_First1, _Last1) to [_First2, ...) _Adl_verify_range(_First1, _Last1); auto _UFirst1 = _Get_unwrapped(_First1); const auto _ULast1 = _Get_unwrapped(_Last1); auto _UFirst2 = _Get_unwrapped_n(_First2, _Idl_distance<_InIt1>(_UFirst1, _ULast1)); if constexpr (_Equal_memcmp_is_safe<decltype(_UFirst1), decltype(_UFirst2), _Pr>) { #if _HAS_CXX20 if (!_STD is_constant_evaluated()) #endif // _HAS_CXX20 { return _Memcmp_ranges(_UFirst1, _ULast1, _UFirst2) == 0; } }
for (; _UFirst1 != _ULast1; _UFirst1, (void) _UFirst2) { if (!_Pred(*_UFirst1, *_UFirst2)) { return false; } }
return true; }
I can't provide my code, for there are several files, but they're available here if it's necessary : https://github.com/DZburst/TP2_Online_Store
Any help would truly be appreciated, Thanks by advance
CodePudding user response:
Client
:
std::ostream& client::operator<<(std::ostream& os, Client& client)
should have been
std::ostream& client::operator<<(std::ostream& os, const Client& client)
// ^^^^^
and for that to work, the member function client::Client::panier()
should be const
qualified and preferably not return a copy of the vector
, but a const&
to the contained vector
. Since you also need a non-const
version in Magasin
I suggest making the function overloaded. In both cases, return by reference:
std::vector<produit::Produit>& client::Client::panier()
// ^
std::vector<produit::Produit> const& client::Client::panier() const
// ^^^^^^ ^^^^^
and
bool client::Client::operator==(Client& client)
should have been
bool client::Client::operator==(const Client& client) const
// ^^^^^ ^^^^^
(or a non-member function taking two Client
s by const&
)
You should also #include <vector>
in Client.h
Produit
bool produit::Produit::operator == (Produit& produit)
bool produit::Produit::operator != (Produit& produit)
should have been
bool produit::Produit::operator == (const Produit& produit) const
bool produit::Produit::operator != (const Produit& produit) const
// ^^^^^ ^^^^^
(or non-members taking two Produit
s by const&
)
With those fixed, it all compiles fine.