我正在尝试这样做:
#include <iostream>
using namespace std;
class smth {
public:
void function1 () { cout<<"before main";}
void function2 () { cout<<"after main";}
};
call function1();
int main ()
{
cout<<" in main";
return 0;
}
call funtion2();
我想传达这样的信息:
“在主要之前”
“在主要”
“在主要之后”
我该怎么做?
你不能。至少不是那样。您应该能够通过将代码放入类构造函数和析构函数中,然后声明一个全局变量来解决它:
struct myStruct
{
myStruct() { std::cout << "Before main?\n"; }
~myStruct() { std::cout << "After main?\n"; }
};
namespace
{
// Put in anonymous namespace, because this variable should not be accessed
// from other translation units
myStruct myStructVariable;
}
int main()
{
std::cout << "In main\n";
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)