Does the address compare enough for this with `operator ==`?

I am creating my own RTTI system for my event system. Below is the class EventTypeInfo. As you can see, this is not possible, just like std::type_info.

class EventTypeInfo
{
  public:
    EventTypeInfo(const EventTypeInfo&) = delete;
    EventTypeInfo& operator=(const EventTypeInfo&) = delete;

    inline bool operator==(const EventTypeInfo& other) const {
        return this == &other;
    }
};

The way to create these objects for each class of events is as follows:

template<class EventClass>
const EventTypeInfo& event::type::info()
{
    static EventTypeInfo typeinfo;
    return typeinfo;
}

Given that (1) these objects are created statically (which means that they will last for the entire duration of the application), (2) they cannot be copied, and (3) there is no way to change the fields EventTypeInfowithout resorting to const_cast, is it enough for me to implement operator==- this terms this == &other, or am I missing something?

+5
source share
4 answers

, , info. , .

, RTTI GCC ​​ , . , GCC GCC 4.5.

, , , .

+2

, - , .

std:: type_info, .

+4

( )

, .

, (), / .

  • , true ( , , "foo", )?
  • false (, )?

, , , : .

, , , false ( ), .

( , , ).

, / , .

, , , , , .

+1

You have not shown us enough class to be sure. Without any data members, there is nothing but an address to determine if they are equal or not. If there are data members that you did not include in your example, is it possible to create two instances that contain the same data? Should these instances be compared as equals?

0
source

All Articles