Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

c++ - Cannot evaluate function -- may be inlined

I wrote a function similar to this:

class abc {
    private :
    int m_var ;
    public :
    int func() { return m_var ; }
};

When I try to print the func() using an abc object pointer in gdb, it is giving the error:

**Cannot evaluate function -- may be inlined**

How to can I print values from an inlined function?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You got this error because you put func's definition in the class body and it's small enough, so, first, the compiler inlined this function ---- that means, the compile will substitute all the appearance of this function's call with its definition, and no definition of this function will be in the executable file. And, second, you didn't really call that function in your program, so in fact, this function never exist in your final executable file!

To solve that:

  1. You can put the definition of func outside the class body.
  2. Call func in your program anywhere.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...