【问题标题】:mErrCount: Identifier not found although it is declared in the include path of Project propertiesmErrCount:虽然在项目属性的包含路径中声明,但未找到标识符
【发布时间】:2015-11-06 06:43:26
【问题描述】:

这是我的代码 test.cpp

#include <test.h>

namespace ScStdTb {

#define CFG_REG 0
#define CMD_REG 0x4
#define CTRL_REG 0x8
#define STAT_REG 0xC

void BasicTB::test()
{
        void testCase();
        
}

void testCase()
{
     unsigned int data = 0x0;
     data=1;
     REG_WRITE(CTRL_REG,&data);

}

}

REG_WRITE 是在 TbCommBase.h 中定义的宏

这是其中的代码 sn-p:

/*macro for register read/write*/
#define REG_WRITE(reg, value) \
    if (send_transaction((reg), value, B_WR)) {\
        mErrCount++;\
        PRINT_DBG("Write failed : Reg at 0x"<< hex << (reg)\
                <<", data 0x"<< value << dec);\
    } else {\
        wait_delta();\
    }

在项目属性中,我添加了 TbCommBase.h 的路径 项目 -> 属性 -> 配置属性 -> C/C++ -> 附加包含目录。

mErrCount 也在 TbCommBase.h

中定义
unsigned int                  mErrCount;

当我尝试编译 test.cpp 时出现以下错误:

错误 C2065:“mErrCount”:未声明的标识符

错误 C3861:'send_transaction':找不到标识符

错误 C3861:“名称”:未找到标识符

错误 C3861:“wait_delta”:找不到标识符

TbCommBase.h 文件中没有错误。它仅在 test.cpp 中显示未声明的标识符,尽管我已经引用了标头。我已经类似地执行了以前的文件,没有任何问题。

有什么想法吗?

【问题讨论】:

  • 也许你需要包含TbCommBase.h。为什么不写一个合适的函数而不是这个长宏???
  • mErrCount 是在哪里定义的?
  • mErrCount 在头文件本身中定义。它已经存在并被许多文件使用。所以我不能把它写成一个单独的函数。
  • @Azad 是对的。您需要在 test.cpp 中包含以下行 #include "TbCommBase.h"
  • TbCommBase.h 包含在 test.h 中,如果没有,您应该将其包含在 test.cpp 中

标签: c++


【解决方案1】:

最后还是很简单的。 范围解析运算符导致了问题。

这是更新后的代码。

#include <ifxPkcTest.h>
namespace ScStdTb {

#define CFG_REG 0
#define CMD_REG 0x4
#define CTRL_REG 0x8
#define STAT_REG 0xC

void BasicTB::test()
{
        void testCase();

}

void BasicTB::testCase()              //SOLUTION
{
     unsigned int data = 0x0;
     data=1;
     REG_WRITE(CTRL_REG,&data);

}

}

【讨论】:

    猜你喜欢
    • 2014-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多