redefinition; multiple initialization

来源:互联网 发布:改进余弦相似度算法 编辑:程序博客网 时间:2024/05/18 01:06

防范式编程
C++头文件写法
test.h

#ifndef __TEST__
#define __TEST__

int i = 100;

#endif

main.cpp

#include “stdafx.h”
#include “test.h”
#include “test.h”

int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}

C++写法
test.h
#pragma once
int i = 100;

main.cpp第二次#include “test.h”的时候发现__TEST__已经被定义了,所以不会执行下面代码。

如果不进行防范式编程,代码会报如下error:
error C2374: ‘i’ : redefinition; multiple initialization

0 0