包括订单效果编译成功 [英] Includes order effects compilation success

查看:69
本文介绍了包括订单效果编译成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在编译需要2个包含以下内容的cirtain .cpp文件时遇到问题:

#include"file1.h"
#include"file2.h"

当按此顺序排列它们时,编译就可以了.更改顺序时,会出现很多这样的编译错误:

... \ winsock2.h(1762):错误C2653:``系统'':不是类或名称空间名称
... \ winsock2.h(1762):错误C2065:``Int16'':未声明的标识符
... \ winsock2.h(1762):错误C2144:语法错误:``u_short''前应加上'')''''
... \ winsock2.h(1762):错误C2448:``HostToNetworkOrder'':函数样式的初始值设定项似乎是函数定义
... \ winsock2.h(1762):错误C2059:语法错误:'')''

这些错误在winsock2.h中的行(1850)重复.
当我在文件winsock2.h中转到第(1762)行时,看不到上述任何名称...

Hi
I have a problem when compiling a cirtain .cpp file which needs 2 includes, say:

#include "file1.h"
#include "file2.h"

When putting them in this order it compiles just fine. When I change their order, I get a lot of compilation errors like this:

...\winsock2.h(1762) : error C2653: ''System'' : is not a class or a namespace name
...\winsock2.h(1762) : error C2065: ''Int16'' : undeclared identifier
...\winsock2.h(1762) : error C2144: syntax error : ''u_short'' should be preceded by '')''
...\winsock2.h(1762) : error C2448: ''HostToNetworkOrder'' : function-style initializer appears to be a function definition
...\winsock2.h(1762) : error C2059: syntax error : '')''

These errors repeat for line (1850) in winsock2.h.
When I go to line (1762) in file winsock2.h I don''t see any of the above names...

Anyone has an idea?

推荐答案

您误解了"include"的含义.这就像使用共享代码资源进行复制和粘贴一样.
例如:

You missunderstood the meaning of "include". This is like copy&paste with sharing code resources.
For example:

// file1.h
#define SUCCESSOR(X)		X+1


// file2.h
#define	INCREMENT(X)		X = SUCCESSOR(X)


// yourcode.cpp

#include "file1.h"
#include "file2.h"

void main()
{
	int		value = 5;
	INCREMENT(value);
}


看起来像:


that looks like:

// yourcode.cpp

#define SUCCESSOR(X)		X+1
#define	INCREMENT(X)		X = SUCCESSOR(X)

void main()
{
	int		value = 5;
	INCREMENT(value);
}


以其他顺序:


in other order:

// yourcode.cpp

#include "file2.h"
#include "file1.h"

void main()
{
	int		value = 5;
	INCREMENT(value);
}



yourcode.cpp



yourcode.cpp

// yourcode.cpp

#define	INCREMENT(X)		X = SUCCESSOR(X) // <- 
// compiler throws a unknown symbol error for ''SUCCESSOR''

#define SUCCESSOR(X)		X+1

void main()
{
	int		value = 5;
	INCREMENT(value);
}



但您也可以通过以下方式进行操作:



but you can do it also in this way:

// file2.h
#include "file1.h"
#define	INCREMENT(X)		X = SUCCESSOR(X)


在这种情况下,必须防止编译器两次包含符号.


in this case you have to prevent the compiler to include the symbols twice.

// yourcode.cpp

#include "file1.h"
#include "file2.h"

void main()
{
	int		value = 5;
	INCREMENT(value);
}



yourcode.cpp



yourcode.cpp

// yourcode.cpp

// #include "file1.h"
#define SUCCESSOR(X)		X+1

// #include "file2.h"
#define SUCCESSOR(X)		X+1 // <- compiler throws a redefined symbol error
#define	INCREMENT(X)		X = SUCCESSOR(X)

void main()
{
	int		value = 5;
	INCREMENT(value);
}



如何预防呢?



how to prevent that?

// file1.h
#ifndef __FILE1_H_INCLUDED
#define __FILE1_H_INCLUDED

#define SUCCESSOR(X)		X+1

#endif // __FILE1_H_INCLUDED


在您的代码中


in your code

// yourcode.cpp

// #include "file1.h"
#ifndef __FILE1_H_INCLUDED
#define __FILE1_H_INCLUDED

#define SUCCESSOR(X)		X+1

#endif // __FILE1_H_INCLUDED

// #include "file2.h"
#ifndef __FILE1_H_INCLUDED // <- compiler ignores code inside this section
#define __FILE1_H_INCLUDED

#define SUCCESSOR(X)		X+1

#endif // __FILE1_H_INCLUDED
#define	INCREMENT(X)		X = SUCCESSOR(X)

void main()
{
	int		value = 5;
	INCREMENT(value);
}


问候.


这不包括……您是.NET引用的程序集和名称空间.
看起来该代码不是您的代码.您可能不知道平台和语言.您的标签显示的是"C ++",但代码不是"C ++",而是"C ++/CLI",至少是其中的一部分.我不知道您从哪里获得u_short,但是其他所有内容都来自.NET.与winsock2.h无关.您需要使用.NET命名空间SystemSystem::Net.

顺便说一句,您认为显示编译错误和不显示各自的代码行不是很好吗?

因此,很难说有人能为您提供帮助.要了解一切,您需要开始编写代码,而要编写更简单的代码,而不是尝试编译您不了解的东西.
也许您需要从头开始:如何创建固定大小的MIDI文件? [ http://en.wikipedia.org/wiki/C%2B%2B/CLI [ ^ ]…

—SA
This is not include… you this is .NET referenced assemblies and name spaces.
It looks like the code is not yours. You probably don''t know the platform and language. Your tag says "C++", but the code is not "C++", but "C++/CLI", at least part of it. I have no idea where you where you get u_short, but everything else is from .NET. It has nothing to do with winsock2.h. You need to use .NET name spaces System and System::Net.

By the way, don''t you think it''s not very nice to show compilation errors and not showing respective code lines?

So, it''s hard to say how anyone can help you. To understand anything you need to start writing your code, much more simple code, instead of trying to compile something you have no idea about.
Maybe, you need to start from the very beginning: How to create a MIDI file with fixed-size?[^], http://en.wikipedia.org/wiki/C%2B%2B/CLI[^]…

—SA


这篇关于包括订单效果编译成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆