The C++ code snippet is:
class A {
public:
A(const std::string& ss, const std::string& tt) :
s(ss), t(tt) {}
void func1() const { std::cout << s; }
void func2() const { std::cout << t; }
using Action = void (A::*)() const;
void test(Action act = &A::func1) const {
(this->*act)();
}
private:
const std::string s;
const std::string t;
};
If I step-by-step debug the following code (it's in main()
, but the webpage incorrectly marks it as SQL):
A a("abc","def");
a.test();
There is no problem. The output is abc
.
However, if I step-by-step debug the following code:
A a("abc","def");
a.test(&A::func2);
The program can still outputs def
as expected, but VS reports the following error when the execution enters the test
member function:
I don't understand the error because my code does not try to open any file. Can you please help me figure out why this error is caused and how to remove it in step-by-step debugging? I am using Visual Studio 2019 on Windows 10. Thanks.