65,210
社区成员
发帖
与我相关
我的任务
分享
// test.h
#ifndef TEST_H
#define TEST_H
template <typename T>
__declspec(noinline) T *GetValue_(void)
{
static T g_value = (T)0;
return &g_value;
}
template __declspec(noinline) int* GetValue_(void);
#define GetValue() GetValue_<int>()
#endif
// output.cpp
#include "test.h"
void Output()
{
*GetValue() = 1;
}
// test.cpp
#include <iostream>
using namespace std;
#include "test.h"
extern void Output(void);
void main(void)
{
Output();
cout << "The value now is: " << *GetValue() << endl;
}
#pragma never_inline
void Test(void)
{
cout << "Hello, world" << endl;
}
__declspec(noinline) void Test(void)
{
cout << "Hello, world" << endl;
}