Alex Rivera | Logout

Breakpoints in inline function not being hit

Asked 2012-10-16T09:38:10.630
10

I have a class declared in the following way:

#ifndef MYCLASS_H
#define MYCLASS_H

class MyClass : public MyOtherClass
{

public:
    MyClass();

    int a() const{ return _a; };
    int b() const{ return _b; };

private:
    int _a;
    int _b;
};

inline bool operator==( const MyClass& lhs, const MyClass& rhs )
{
    return (lhs.a() == rhs.a()) && (lhs.b() == rhs.b());
}

#endif

My problem is that any breakpoints is set in the overloaded operator== never get hit, with Visual Studio even telling me that execution will never reach this function. I've followed this rule of thumb for overloading comparison operators, but it doesn't mention anything other than to make them non-members, so I'm not sure if I've missed something with operator overloading or inline functions.

Can anyone tell me why my breakpoints are never being hit?

Edit
Report

1 Answer

0

inline doesn't mean that function body will be inlined in every call site. Actually, function can be inlined by the compiler even if it is not explicitly defined inline. And one function can be inlined in one call site and called normally in another call site. This directive is just a hint to the compiler. Visual studio debugger works fine with inlined functions.

I think this problem doesn't caused by the inline directive. Try to remove this directive and run your code under debugger. And it is very handy to write unit test for cases like this.

answered 2012-10-16T09:51:19.200

Your Answer