简体   繁体   English

C ++包括不起作用

[英]C++ including doesn't work

On the last several hours I'm trying desperately to figure out what is wrong, but in vain: 在过去的几个小时里,我拼命尝试找出问题所在,但徒劳无功:

I have the following scenario: I had a working header, and I decided to move parts from it to a new another file. 我有以下情形:我有一个有效的头,并且我决定将部件从其中移动到另一个新文件。

So basically I have now: 所以基本上我现在有:

FileA 文件A

......
class A;
.....

File B 文件B

#include FileA
.....
A B;
.....

But the variable A doesn't get recognized in fileB at all. 但是变量A根本不会在fileB中被识别。

  • All the definitions are under the same namespace 所有定义都在同一个命名空间下
  • Nothing is misspelled 没有错
  • I'm using in the boost library and on debug mode I get : "intelisence: incompatible build options" (dont know yet if this connected or not to my problem) 我在boost库和调试模式下使用:“ intellisence:incompatible build options”(尚不知道这是否与我的问题有关)
  • When looking on the code, the visual studio recognized all the types (ie when pressing on the type "A" in file B, the visual studio recognized it). 查看代码时,Visual Studio会识别所有类型(即,按下文件B中的类型“ A”时,Visual Studio会识别出它)。

What am I doing wrong? 我究竟做错了什么?

Following you request for the real code and further details: Let me be more specific I'm using the ifndef method and probably this causing to the mess, but I dont see why since fileB is the only one who includes fileA 以下是您要求的真实代码和更多详细信息:让我更具体一点,我正在使用ifndef方法,这很可能导致混乱,但是我不明白为什么,因为fileB是唯一包含fileA的人

The code itself looks like this: 代码本身如下所示:

    #ifndef MERKLE_BASICS_HPP
    #define MERKLE_BASICS_HPP
    #include "FullProofConsumer.hpp"
    #include <openssl\sha.h>
    namespace PCP_Project{
typedef unsigned char* HashDigest;
//Forward Declarations
HashDigest hashTwoElements(HashDigest,HashDigest);
HashDigest hash_GF2E_Element (GF2E);
HashDigest createZeroCommitment();
//The definition of the hashDigest type, for now its just long. Will be probably       replacedlater. 
//typedef unsigned char* HashDigest;

     }
    #endif

And then on the other file I have: 然后在另一个文件上,我有:

                #ifndef MERKLE_CONSUMER
                #define MERKLE_CONSUMER
                #include <fstream>
                #include "MerkleBasics.hpp"
                 namespace PCP_Project{
                 ......

                 HashDigest Value;
                  ...

And the compilation Error: Error 273 error C2146: syntax error : missing ';' 和编译错误:错误273错误C2146:语法错误:缺少';' before identifier 'Value' 在标识符“值”之前
(I have plenty of those, this is just one example) Sorry if from the original question you understood something defferent, and thanks again (我有很多,这只是一个例子)对不起,如果从最初的问题中您理解了一些不同的观点,再次表示感谢

It looks like in file A, you only have a forward declaration of the class: 看起来在文件A中,您只有该类的前向声明:

class A;

That means you don't have a complete definition of the class, and thus unable to use instances of it - you can however use pointers. 这意味着您没有该类的完整定义,因此无法使用它的实例-但是,您可以使用指针。

You'll have to post more code for more help (properly formatted). 您必须发布更多代码以获得更多帮助(格式正确)。

Looking at the description of your problem I take a random guess - have you by accident placed the SAME INCLUDE GUARDS in both the files ? 查看问题的描述,我会做出一个随机猜测-您是否偶然将SAME INCLUDE GUARDS放在了两个文件中? In that case the include A will not work at all. 在这种情况下,包含A根本不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM