-2

When I use CMake to compile my program. I faced with this error.

framework/base.h:146:30: 错误:expected unqualified-id before ‘&’ token
         catch(std::bad_typeid& e)

my program is posted up as followed:

 void Do()
    {        bool ret = false;
        try
        {
            ret = run();
        }
        catch(std::bad_typeid& e)
        {
            std::cerr << e.what() << '\n';
            errMsg = e.what();
            ret = false;
        }
        catch(...)
        {
            std::cerr << "unknown error" << '\n';
            errMsg = "unknown error";
            ret = false;
        }
    }

CMakeLists.txt:

include_directories(../common)

because this function defines in a Header file. some other modules include this file to use the function do(). So I just write a include_directories() statement in CMakeLists.txt.

6
  • 4
    Welcome to Stack Overflow! Please add the CMake code to your question post as text. Also, please do not post images of code; rather, add your source code (and full error message) to your question post as text. Consider reading through the How to Ask section of the site.
    – Kevin
    Apr 10, 2020 at 11:50
  • virtual void Do() { bool ret = false; try { ret = run(); } catch(std::bad_typeid& e) { std::cerr << e.what() << '\n'; errMsg = e.what(); ret = false; } catch(...) { std::cerr << "unknown error" << '\n'; errMsg = "unknown error"; ret = false; } }
    – Zheng Yun
    Apr 10, 2020 at 11:56
  • 1
    Did you #include <typeinfo>?
    – G.M.
    Apr 10, 2020 at 11:57
  • this is a part of my function, which runs ok in windows, but failed in Linux.
    – Zheng Yun
    Apr 10, 2020 at 11:57
  • 1
    Please provide a minimal reproducible example. Apr 10, 2020 at 14:56

1 Answer 1

0

i include the header file by include file <new> finally, it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.