Wednesday, 15 September 2010

c++ cli - C++/CLI : How to override Equal method of Object class -


I am a newbie for C ++ / CLI and there are some issues with overriding the same method as the base object class. Are there. I get the following compilation warning error for the following code. How should it be corrected?

  Warning 1 Warning C4490: 'Override': Incorrect use of override specifier; 'Test :: Sample :: Equivalent' base referee does not match class method c: \ project \ code \ Sample.h 18 error 2 error LNK2022: Metadata operation failed (80131187): Incompatible method announcements in duplicate types (type: Test Sample; Method: Equal): (0x06000002) 3: I removed the overridden keyword in the source file, by replacing "Equals" with "Equals", but error 2 still stands.  

/ / header file

  public ref class sample: public object {public: int someVariable; Override virtual bull equivalent (object obj); Virtual It's Hoshcode () Override; }  

// source file

  bool sample :: equals (object ^ obj) {if (obj == nullptr GetType ()! = Obj-> GetType ()) returned incorrectly; Sample ^ p = dynamic_cast & lt; Sample ^ & gt; (Obj); Return (some variables == P- & gt; some variables); } ET Sample :: GetHashCode () {return GetHashCode (); }   

The method's name is not identical Code> equals . You should not use the virtual or override keyword in the implementation:

  Ref class test {public: Virtual Bull Equals (Object ^ o )) Override; Virtual It's Hoshcode () Override; }; Bool test :: equal (object ^ o) {// no "override" here // ...} int test :: GetHashCode () {// no "override" here // ...}  < / Pre> 

1 comment: