我可以采取哪些步骤来删除代码中的错误?

kum*_*mar -1 macos cocoa iokit

我通过以下方式在I/O Kit驱动程序模板中编写代码:

#include <IOKit/IOService.h>
class com_osxkernel_driver_IOKitTest : public IOService
{
  OSDeclareDefaultStructors(com_osxkernel_driver_IOKitTest)
   public:
        virtual bool    init (OSDictionary* dictionary = NULL);
        virtual void    free (void);
        virtual IOService*      probe (IOService* provider, SInt32* score);
        virtual bool    start (IOService* provider);
        virtual void    stop (IOService* provider);
}; 
#include "IOKitTest.h"
#include <IOKit/IOLib.h>
#define super IOService
OSDefineMetaClassAndStructors(com_osxkernel_driver_IOKitTest, IOService)
bool com_osxkernel_driver_IOKitTest::init (OSDictionary* dict)
{
    bool res = super::init(dict);
    IOLog("IOKitTest::init\n");
    return res;
}
void com_osxkernel_driver_IOKitTest::free(void)
?{
    IOLog("IOKitTest::free\n");
    super::free();
} 
IOService* com_osxkernel_driver_IOKitTest::probe (IOService* provider, SInt32* score)
{
    IOService *res = super::probe(provider, score);
    IOLog("IOKitTest::probe\n");
    return res;
}
bool com_osxkernel_driver_IOKitTest::start (IOService *provider)
{
     bool res = super::start(provider);
     IOLog("IOKitTest::start\n");
     return res;
}
void com_osxkernel_driver_IOKitTest::stop (IOService *provider)
{ 
    IOLog("IOKitTest::stop\n");
    super::stop(provider);
}
Run Code Online (Sandbox Code Playgroud)

当我构建此代码时,我得到四个错误:

  1. 函数声明符后的预期函数体
  2. stray '\357' in program
  3. stray '\277' in program
  4. stray '\274' in program

你能看到错误吗?

Mat*_*uch 10

你能看到错误吗?

不,但编译器可以.Xcode会向您展示.

我将您的代码粘贴到一个新项目中并编译它:

在此输入图像描述

所有三个杂散字符都在代码的相同部分.
如果stray '\something'发生这样的错误,您的代码中有一个无法编译的字符,而您通常无法看到它们.它们通常来自错误的复制和粘贴.

只需删除带有错误的行并再次写入.不要复制和粘贴或任何东西.

我拿了那部分代码并在十六进制编辑器中打开它.所以你可以看到这些错误的来源.

在此输入图像描述

  • 别客气.如果它帮助你考虑接受它.为此,请单击问题旁边的复选标记. (2认同)