导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→[转帖]如何在XC中使用CLASS?[liufengzhong]

 *第63735篇: [转帖]如何在XC中使用CLASS?

  
楼 主:liufengzhong 2014年8月4日14:15
 [转帖]如何在XC中使用CLASS?
我创建了一个名为SPI的class,我想做出一个SPI类的class,HANDELS所有的SPI接口。创建工程后,我得到多奇怪的错误。class spi { public: spi(); virtual ~spi(); }; 接下来我得到以下错误:spi.h:24: warning: type defaults to `int' in declaration of `class' spi.h:24: warning: data definition has no type or storage class spi.h:24: error: parse error before "spi" In file included from ../src/main.xc:10: spi.h:24: error: invalid declarator for function declaration spi.h:24: warning: return type defaults to `int' spi.h: In function `spi': spi.h:25: error: `public' undeclared (first use in this function) spi.h:25: error: (Each undeclared identifier is reported only once spi.h:25: error: for each function it appears in.) spi.h:26: error: parse error before ';' token spi.h:27: warning: type defaults to `int' in declaration of `virtual' spi.h:27: warning: data definition has no type or storage class spi.h:27: error: parse error before '~' token spi.h:27: warning: return type defaults to `int' spi.h: At top level: spi.h:28: error: parse error before '}' token ../src/main.xc:13: error: local variable `spi_if' has type that contains a port ../src/main.xc: In function `main': ../src/main.xc:24: error: `SPI' undeclared (first use in this function) ../src/main.xc:24: error: parse error before "SPI1" ../src/main.xc:26: error: parse error before "return" ../src/main.xc:27: error: parse error before '}'    
提前致谢


回答:


XC是不是用C+ +类兼容。在C + +文件中声明了的extern“C”的功能,和从XC中调用它。

例如:
// xcc -target=XS1-L16A-128-QF124-C10 spi.xc spi.cpp -o spi.xe// spi.xc

void spi_cpp();
int main()
{
  spi_cpp();
  return 0;
}
// spi.cpp
#include   <print.h>  
extern "C" void spi_cpp()
{
  printstrln("Hello from C++!");
}


>>>>>>对该主题发表你的看法

本主题贴数1,分页: [第1页]


[上一篇主题]:[转帖]Startkit ADC怎么样,有什么官方的例子吗?

[下一篇主题]:[转帖]xTIMEcomposer不能在Ubuntu 14.04 64-bit&