0

我有 ADC 和其他外围设备的供应商特定代码。现在使用它我正在理解流程。

文件的扩展名为 .cpp,但其中的语句类似于 C 而不是 C++,即使用 printf() 而不是 cout;没有定义 namespace.std ......还有其他让我确信它是 c 语言代码的东西。(请原谅我,但无论我问供应商,但从那里回复很晚)

所以它是一个完整的 C 代码。但是,虽然我明白了,但我已经到了定义类的地步,我现在真的很困惑。因为我没有看到或听到任何人使用类

C4DSPBlast cBlast;
cBlast.GetBlastInfo();

其中 C4DSPBlast cBlast;

以下代码显示 C4DSPBlast 是一个类。现在,在调试时,我发现我在这条语句 cBlast.GetBlastInfo(); 上遇到了错误。但是因为我不知道 C 中的类,所以我把它贴在这里,因为我在调试方面没有任何进展。

class C4DSPBlast
{
public:

    //! empty constructor.
    C4DSPBlast(void);
    //! empty destructor.
    ~C4DSPBlast(void);

    //! Get BLAST information from the hardware(firmware). 
    /*!
     * Read the BLAST information from an the PCI memory attached to the hardware device. This function populates internal class members with this information.
     * @return  CBLAST_IO_ERROR_BLAST_INFO_RD, CBLAST_NO_DEV_TYPE or CBLAST_SUCCESS if no errors.
     */
    int GetBlastInfo(void);

    //! m_valBLASTRegister the standard BLAST information register.
    union { BLASTReg m_BLASTRegister; unsigned long m_val0; } m_valBLASTRegister;   

    //! m_valBLASTRegisterExt the extended BLAST information register.
    union { BLASTReg m_BLASTRegisterExt; unsigned long m_val1; } m_valBLASTRegisterExt;

    //! The whole BLAST information populated by GetBlastInfo() as a C data structure.
    struct BOARD m_cBoard;
};
4

2 回答 2

4

代码是 C++。将其编译为 C++,错误将消失。

于 2012-07-06T11:09:07.413 回答
1

C 和 C++ 是不同的语言。当前的常见约定是,如果您将带有扩展名的文件提供.c给编译器,它会将其编译为 C 文件。如果你给它一个.cppor .cxx(确切的列表取决于编译器),它将把它作为 C++ 文件处理。即使您将 C/C++ 文件的混合放在同一命令行上,这也将起作用。

如果你选择任意 C 文件,重命名为.cpp,然后交给编译器,99% 的几率会被编译。C++ 标准描述了与 C 不兼容的列表,但这些都是相当罕见的事情。

您很可能会看到一个以 C 语言创建的文件,然后以 C++ 开始了它的新生命。

于 2012-07-06T10:16:21.677 回答