これは私のヘッダーファイルです、auto vs static.h
#include "stdafx.h"
#include <iostream>
void IncrementAndPrint()
{
using namespace std;
int nValue = 1; // automatic duration by default
++nValue;
cout << nValue << endl;
} // nValue is destroyed here
void print_auto()
{
IncrementAndPrint();
IncrementAndPrint();
IncrementAndPrint();
}
void IncrementAndPrint()
{
using namespace std;
static int s_nValue = 1; // fixed duration
++s_nValue;
cout << s_nValue << endl;
} // s_nValue is not destroyed here, but becomes inaccessible
void print_static()
{
IncrementAndPrint();
IncrementAndPrint();
IncrementAndPrint();
}
そしてこれが私のメインファイルnamearray.cppです
#include "stdafx.h"
#include <iostream>
#include "auto vs static.h"
using namespace std;
int main(); // changing this to "int main()" (get rid of ;) solves error 5.
{
print_static();
print_auto();
cin.get();
return 0;
}
印刷しようとしています(cout)2 2 2 2 3 4
エラー:
私の間違いは、ヘッダーファイルでvoidを使用しているだけだと感じています。コードが機能するようにヘッダーファイルを変更するにはどうすればよいですか?