【问题标题】:C++: Syntax error C2061: IdentifierC++:语法错误 C2061:标识符
【发布时间】:2013-05-06 19:34:10
【问题描述】:

我有一个非常奇怪的问题。

在我的标题“compier.h”中,我有以下原型:

void WriteMap(FILE *outfile,clsMapping &uMap);

在 cpp 中我这样声明:

void CCompiler::WriteMap(FILE *outfile,clsMapping &uMap)
{
    int iSize = uMap.Content().size();
    fwrite(&iSize,sizeof(int),1,outfile);

    int iOffset=uMap.iOffset;

    fwrite(&iOffset,sizeof(int),1,outfile);

    vector<udtMapping>::iterator it = uMap.Content().begin();
    int n = 0;
    for (;it != uMap.Content().end(); ++it)
    {
        fwrite( &it->ByteStart, sizeof(int), 1, outfile);
        fwrite( &it->ByteCount, sizeof(int), 1, outfile);
    }   
}

编译器告诉我 “语法错误 C2061:标识符‘clsMapping’。 它告诉我:

该声明与“”void CCompiler::WriteMap(FILE *outfile, &uMap)“(在“m:\app\compiler.h”第30行声明)”不兼容。

clsMapping 在头文件“structures.h”中声明:

class clsMapping
{
private:
    vector<udtMapping> m_content;

protected:

public:
    vector<udtMapping> &Content();
    void Add(int i1, int i2);
    int iOffset;
    void FeedFeaturesFromMap(udtFeatures &uFeatures,int uIndex);
};

在 compiler.h 中我已经说明

#include "structures.h"

我是否忽略了一个错字,还是更严重的问题?

感谢您的帮助。

【问题讨论】:

  • clsMapping 是一个类吗?您确定在此文件中声明或包含声明吗?
  • 除了这个错误还有什么?
  • 在哪里报错? clsMapping 在哪里声明,如何声明?
  • 很好,但你确实说过'在 compiler.h 我已经声明了#include "structures.h"'。
  • 是的,我错了。我将它添加到 compiler.cpp,但没有添加到 compiler.h

标签: c++ windows


【解决方案1】:
#include "structures.h"

必须同时添加到 cpp 和 h 文件中。

【讨论】:

    猜你喜欢
    • 2011-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-07
    相关资源
    最近更新 更多