Breakpoint will not currently be hit. No executable code associated with this line

后端 未结 9 1749
感情败类
感情败类 2021-01-07 23:50

I have a class in a .h file:

class Blah
{
public:
    Blah(){}
    virtual ~Blah(){}

    void WriteMessage( bool MessageReceived )
    {
        if(MessageR         


        
9条回答
  •  不要未来只要你来
    2021-01-08 00:26

    I had the same issue but the accepted solution of cleaning up files didn't work for me. I have my issue resolved and it had to do with my code. Here are the details of my fix, hope it gives some clues to your fix.

    What I was doing is overloading CArchive << operator for my structure but the code never steps into it. I would set the break point and I got the solid red symbol. As soon as I start debugger the symbol becomes outlined and the warning message on it says:

    The breakpoint will not currently be hit. no executable code is associated with this line

    My relevant code is below where the break point doesn't break.

    class Book
    {
         friend CArchive& operator << (CArchive& ar, const Book & book )
         {
    
             ar << book.title;
             ar << "\r\n";
             ar << book.price;
             ar << "\r\n";
         }
    }
    

    Now there is an obvious problem with this code is that it doesn't have a return statement return ar but the compiler never complained. The reason compiler didn't complain was I was using the operator incorrectly (and rather never using it)

    book *mybook = new Book(...);
    ar << mybook;
    

    Because mistakenly I am accessing the operator via pointer, my object's << operator was never really invoked and that's why compiler didn't complain either because it was never being used.

    So first I fixed the calling code

    book *mybook = new Book(...);
    ar << *mybook;
    

    Now the operator overloading method complains about the return statement and I fixed that too.

    I can now step into the function. So the bottom line was that the break point was not being set because this code was essentially sidelined by compiler (correctly) because it was never used in the code.

提交回复
热议问题