oc怎么调用下面的c++函数
//发送的报文staticunsignedcharsendframe[512];//发送的报文长度staticintsendframelen=0;unsignedchar...
//发送的报文
static unsigned char sendframe[512];
// 发送的报文长度
static int sendframelen = 0;
unsigned char *ctrl_fn003_send (unsigned char *termaddr, unsigned char A3,
int mpNo, unsigned char fromphase, unsigned char tophase)
{
int datalen = 0;
unsigned char afn = 0, databuf[32];
unsigned short fn = 0;
memset (sendframe, 0, sizeof (sendframe));
memset (databuf, 0, sizeof (databuf));
afn = 0x05;
fn = 3;
databuf[0] = ((fromphase << 4) & 0xF0) | (tophase & 0x0F);
datalen = 1;
make_send_376_frame (termaddr, A3, mpNo, afn, fn,
databuf, datalen, sendframe, &sendframelen);
return sendframe;
} 展开
static unsigned char sendframe[512];
// 发送的报文长度
static int sendframelen = 0;
unsigned char *ctrl_fn003_send (unsigned char *termaddr, unsigned char A3,
int mpNo, unsigned char fromphase, unsigned char tophase)
{
int datalen = 0;
unsigned char afn = 0, databuf[32];
unsigned short fn = 0;
memset (sendframe, 0, sizeof (sendframe));
memset (databuf, 0, sizeof (databuf));
afn = 0x05;
fn = 3;
databuf[0] = ((fromphase << 4) & 0xF0) | (tophase & 0x0F);
datalen = 1;
make_send_376_frame (termaddr, A3, mpNo, afn, fn,
databuf, datalen, sendframe, &sendframelen);
return sendframe;
} 展开
1个回答
2018-10-23 · 百度知道合伙人官方认证企业
关注
展开全部
2.在test.h文件中定义方法
#ifndef __test__
#define __test__
class Test
{
public:
void test();
static void testStatic();
};
#endif
2.1.在test.cpp中实现定义的方法
#include "test.h"
#include <iostream>
void Test::test()
{
printf("Hellow world \n");
}
void Test::testStatic()
{
printf("Hellow world with Static");
}
3.在RootViewController.h文件中定义oc需要调用的方法
-(void)testFunc;
3.1在RootViewController.mm文件中实现上方法,并且和c++文件建立联系
#import "RootViewController.h"
#include "test.h"
static Test* pTest=NULL;
@implementation testObject
-(id)init
{
if (self=[super init]) {
if (!pTest) {
pTest=new Test();
}
}
return self;
}
-(void)testFunc
{
if (pTest) {
pTest->test(); //-> c++ 指针 调用 公有变量和方法
//. c++ 对象 调用 公有变量和方法
}
Test::testStatic();
}
- (void)dealloc {
if (pTest) {
delete pTest;
}
[super dealloc];
}
@end
4.在viewControler的viewdidLoad方法中实例化一个RootViewController对象并且调用在RootViewController.h声明的方法
testObject * ttt=[[testObject alloc] init];
[ttt testFunc];
5.运行查看打印结果
#ifndef __test__
#define __test__
class Test
{
public:
void test();
static void testStatic();
};
#endif
2.1.在test.cpp中实现定义的方法
#include "test.h"
#include <iostream>
void Test::test()
{
printf("Hellow world \n");
}
void Test::testStatic()
{
printf("Hellow world with Static");
}
3.在RootViewController.h文件中定义oc需要调用的方法
-(void)testFunc;
3.1在RootViewController.mm文件中实现上方法,并且和c++文件建立联系
#import "RootViewController.h"
#include "test.h"
static Test* pTest=NULL;
@implementation testObject
-(id)init
{
if (self=[super init]) {
if (!pTest) {
pTest=new Test();
}
}
return self;
}
-(void)testFunc
{
if (pTest) {
pTest->test(); //-> c++ 指针 调用 公有变量和方法
//. c++ 对象 调用 公有变量和方法
}
Test::testStatic();
}
- (void)dealloc {
if (pTest) {
delete pTest;
}
[super dealloc];
}
@end
4.在viewControler的viewdidLoad方法中实例化一个RootViewController对象并且调用在RootViewController.h声明的方法
testObject * ttt=[[testObject alloc] init];
[ttt testFunc];
5.运行查看打印结果
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询