0

I have a header file test.h

 #ifndef __visibilty_test__test__

 #define __visibilty_test__test__

 #include <iostream>

using namespace std;

class test{

public:

    void print(string s);
};

 #endif 

and test.mm

 #include "test.h"

using namespace std;


void test:: print(string s){

    cout << s << endl;

}

now I want to call print function in my AppDelegate.m file in an iOS Application. Can anyone help me?

Thanks in advance

Mark
  • 8,046
  • 15
  • 48
  • 78
Sumit Kumar
  • 402
  • 1
  • 6
  • 26
  • `test.mm` should be called `test.cpp` as it's pure C++. – trojanfoe Jun 06 '13 at 07:18
  • possible duplicate of [Problem when #import C++ Header File in iPhone/iPad Project](http://stackoverflow.com/questions/3890552/problem-when-import-c-header-file-in-iphone-ipad-project) – Parag Bafna Jun 06 '13 at 07:20

2 Answers2

2
  1. Rename AppDelegate.m to AppDelegate.mm.

  2. Call the method as you would in C++:

    test t;
    t.print("Hello");
    
trojanfoe
  • 120,358
  • 21
  • 212
  • 242
0

Your object:

#include <iostream>

 using namespace std;

 class test
 {
     public:
         void print(string s)
         {
             cout << s << endl;
         }
 };

call from mm file

test *t = new test;
t->print("hello");
Jabson
  • 1,585
  • 1
  • 12
  • 16