I'm trying to do this:
#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();
and i want to have this message: " before main" " in main" "after main"
How can I do it?
You can't. At least not that way. You should be able to solve it by putting the code in a class constructor and destructor, then declaring a global variable:
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";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With