简体   繁体   中英

C++ Code in Objective-C for iOS

Schleife.h

#ifndef __CPlusPlusTest__Schleife__
#define __CPlusPlusTest__Schleife__

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

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

#import <UIKit/UIKit.h>

#import "Schleife.h"

@interface ViewController : UIViewController

@end

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'"

I don't understand what I did wrong. I want just implement C++ Code in my App. 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

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

private:
    int ergebnis;
};

you will also need to include #include "Schleife.h" in your ViewController.mm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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