Sunday 15 August 2010

compiler errors - C++ Invalid arguments, Candidates are : ".." on Setters from different classes -


There is a strange error that I could not solve.

I have some files, Store.cpp, Store.h (class store is defined here), Order.cpp, Order.h (class order is defined here).

#include "order.h" in Store.cpp.

I have some sets and gates in the public section, one of them is:

  Zero Setstats (Const. OrderStatus End) Order status);   

OrderStatus is an enumeration.

When I'm trying to use it in Store.cpp from the following:

  (* ITR) .setStatus (ORDER_DONE);   

I get this error from eclipse: Invalid logic 'candidates are: Zero setstats (Constant Emam {order.h: 140} & amp; / Pre>

and this error from GCC:

 Store.cpp: 250: 31: Error: There is no match for calling to order: setStatus (OrderStatus) constà ¢ Store Cpp: 250: 31: Note: The candidate is: 
order.h: 47: 7: Note: Zero order :: Setstats (Const. Orderstats & amp;) order.h: 47: 7: Note: No known conversion for unbalanced ¢  ¢ Order to ÃÆ'à ¢ â,¬Å¡Ãƒâ € šÃ, ¢ ÃÆ'à ¢ â,¬Å¡Ãƒâ € šÃ, © Where I came from const actually Do not know (Line 250).

std :: set unchangeable value type Used to store them should be irreversible, because otherwise you can break the barriers randomly while changing them.

If you want to add a convertible value to a key (which is irreversible for that reason), instead of std :: map Use.


There are mechanisms about it:

  std :: set & lt; Order & gt; :: Iterator IARR = ...; Iter- & gt; SetStatus (ORDER_DONE);   

does not work because * iter yields order treaty and and your method is not const.

I mentioned in a comment that there are two ways to avoid the problem, but both of them do this by changing the exact purity, and I recommend using one of them I not but, for completeness:

  const_cast & lt; Order & amp; & Gt; (* Iter) .setStatus (ORDER_DONE);   

This will compile, as the order changes in the class itself:

  class command {mutual orderstats status; Public: Zero setstats (orderstats) const {status = s; }};   

Any of these can be irreversible in the order of std :: set if the status is used in comparison, the first version says "just trust me" And is completely right in the right way, while the other clearly states that the condition is not the "real" part of the state of the object and it will not be used for sorting.

Seriously, instead use the right data structure.

No comments:

Post a Comment