在my.h文件中定义了一个结构体,然后在my.cpp中包含该my.h文件
但是编译时出错,说是结构体中的有些参数重新定义了
头文件my.h如下
#ifndef _my_h
#define _my_h
struct DATA
{
int a;
int b;
int c;
};
viod Fuction();
#endifmy.cpp中
#include "StdAfx.h
#include "my.h"
void Fuction()
{}觉得这样应该没问题的吧
但是提示struct中有些参数重定义了
为什么会是一部分参数重定义而不是全部呢?哪里出了问题呢?
但是编译时出错,说是结构体中的有些参数重新定义了
头文件my.h如下
#ifndef _my_h
#define _my_h
struct DATA
{
int a;
int b;
int c;
};
viod Fuction();
#endifmy.cpp中
#include "StdAfx.h
#include "my.h"
void Fuction()
{}觉得这样应该没问题的吧
但是提示struct中有些参数重定义了
为什么会是一部分参数重定义而不是全部呢?哪里出了问题呢?
#define _my_h
struct DATA
{
int a;
int b;
int c;
};
viod Fuction();
#endif my.cpp中
#include "StdAfx.h
#include "my.h"
#ifndef _my_h
void Fuction()
{ }
#endif既然你h中用了条件便宜,CPP中也应该用上吧。如果没定义_my_h CPP当然会报错拉
#include "StdAfx.h
#include "my.h"
#ifndef _my_h
void Fuction() 这个里面不要
#ifndef _my_h
void Fuction()
{ }
错了,应该是void ....
至于说结构体重定义的错误,请把错误信息贴出来,应该不会有错的.
上面有位哥们说要在CPP中也添加#ifndef...,是错误的,那样会造成CPP中的内容都不被编译,LZ不要听.