c++ – header code in visual studio is not synced while debugging


i know it’s not a good practice to place code in header files but i am in testing phase and i don’t want to sophisticate the project with so many hpp/cpp pairs early on.

i did clean/rebuild, recreate database and as a last resort deleted the .vs folder but the problem still annoys me.

when a breakpoint hits, i land at ~7 line above where i should.
it doesn’t matter what kind of code it is or upon what event (bp hit, step in, exception), i land at incorrect spot.

this snippet for example:

MyType& operator=(const MyType& other) {
        if (this != &other) {
            m_id = other.m_id;
            m_size = other.m_size;
            m_dt = other.m_dt;
        }
        return *this;
    }

and then:

MyType b{};
MyType a = b;

i land above the overloaded operator.

i am using #pragma once. i am also using #pragma pack, other than this, everything else is either enum or struct. i am using the default “Debug” configuration so i suppose every optimization option is off.
even if i add a .cpp pair, tiny code snippets like constructors and simple methods are supposed to be in header.
this whole situation is a mystery to me, i cant clarify the matter that is not very clear to me!

Leave a Reply

Your email address will not be published. Required fields are marked *