简体   繁体   中英

Conditional breakpoint in Visual Studio - condition using non basic data types

Is it true that the condition in a conditional breakpoint can only have the basic datatypes (ie int , float , bool , etc). Say for example I have defined NULL for an object of a class MyClass as NULL_OBJ . And I have in my code an object MyClass myclassobject . Could I put a condition as myclassobject==NULL_OBJ in a breakpoint?

Assuming you do not want to compare object pointers to null pointer, which is trivial; yes, you can put such a condition.

However, you need to overload equality operator == for related MyClass :

class MyClass
{
    public:
        MyClass()
        {
           someMember = 0; // let this be null object condition
        }
        MyClass(int member)
        {
           someMember = member; 
        }
        bool operator == (const MyClass &Ref) const 
        {
            return(this->someMember== Ref.GetMember());
        }

        const int GetMember() const
        {
            return(this->someMember);
        }

    private:
        int someMember;
};

#define NULL_OBJ MyClass()

By #define NULL_OBJ MyClass() , you can define a null object and compare any MyClass object with it.

(with the reference )

您可以获取对象的地址,并与通常进行比较。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM