简体   繁体   English

适用于iOS的Objective-C中的C ++代码

[英]C++ Code in Objective-C for iOS

Schleife.h Schleife.h

#ifndef __CPlusPlusTest__Schleife__
#define __CPlusPlusTest__Schleife__

#include <iostream>
class Schleife;
#endif /* defined(__CPlusPlusTest__Schleife__) */

Schleife.cpp Schleife.cpp

#include "Schleife.h"

class Schleife
{
public:
    int addition(int,int);

private:
    int ergebnis;
};


int Schleife::addition(int a,int b)
{
    ergebnis = a +b;
    return ergebnis;
}

ViewController.h ViewController.h

#import <UIKit/UIKit.h>

#import "Schleife.h"

@interface ViewController : UIViewController

@end

ViewController.mm ViewController.mm

#import "ViewController.h"



@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
     Schleife *schleife = new Schleife();
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

Whats Wrong? 怎么了?

I got the Error Message: "ViewController.mm:22:31: Allocation of incomplete type 'Schleife'" 我收到了错误消息:“ViewController.mm:22:31:不完整类型'Schleife'的分配”

I don't understand what I did wrong. 我不明白我做错了什么。 I want just implement C++ Code in my App. 我想在我的应用程序中实现C ++代码。 So I started with a easy example but it doesn't work... Can you help me? 所以我从一个简单的例子开始,但它不起作用......你能帮助我吗? I know its maybe a easy Questions but I can't find the mistake... 我知道它可能是一个简单的问题,但我找不到错误......

Schleife.h should have this code instead of the cpp file Schleife.h应该有这个代码而不是cpp文件

class Schleife
{
public:
    int addition(int,int);

private:
    int ergebnis;
};

you will also need to include #include "Schleife.h" in your ViewController.mm 您还需要在ViewController.mm中包含#include“Schleife.h”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM