• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Objective-C++
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective-C++


  • Subject: Re: Objective-C++
  • From: Philip Bridson <email@hidden>
  • Date: Sat, 9 Feb 2008 00:02:02 +0000

OK that makes a lot of sense. One final question: when creating a new project should I still create a new Cocoa app or should I create something else?

Thank you for your help.

Phil.

On 8 Feb 2008, at 23:55, Herb Petschauer wrote:

If you have a ".m" that you expect to be able to user your C++ classes
then you will have to rename it to .mm.

If you have information in your .h files that a .m file needs but that
isn't C++ specific (e.g. struct, enum) then just protect all of the
C++ info and leave the other stuff exposed.

Switching everything over to .mm is probably your quickest bet.  It
will slow your compile times down somewhat (this has been discussed
recently, Jan 30th, "programming in C++").

Cheers,
-H.

On 08/02/2008, Philip Bridson <email@hidden> wrote:
Yeah it is. I use Obj-C to handle all the UI parts of my app and C++
to do all the "background" work. So generally all my C++ classes are
included and called by Obj-C Objects.

Phil.

On 8 Feb 2008, at 23:44, Herb Petschauer wrote:

Extend the #ifdef __cplusplus to everything in your header file that
is C++ code.

Your header file must be being included (wow, bad grammar) by a non
C++ file (do you have any .m's in your project?).  Say timmy.m is
including your C++ header file.  timmy is being compiled by the ObjC
compiler, it doesn't know anything about the word "class" or the std
namespace.

Cheers,
H.

On 08/02/2008, Philip Bridson <email@hidden> wrote:
Thank you for your response, this is what happened:


#ifdef __cplusplus #include <iostream> #include <string.h> #endif

#define SECONDS_PER_MINUTE 60
#define MINUTES_PER_HOUR 60

using namespace std; //parse error before namespace

class Counter //syntax error before counter
{
private: //parse error before :
string myString; //parse error before myString
}; //parse error before }

This is in my header file not my .mm file.

Phil.





On 8 Feb 2008, at 23:31, Herb Petschauer wrote:

Seriously, add the #ifdef __cplusplus from my previous response :-)

On 08/02/2008, Philip Bridson <email@hidden> wrote:
OK then, I am now none the wiser because that is what I have been
doing all along.

To be more precise I declare a class as follows:

This is my header file...

MyClass.h

#include <iostream>                             //Here is where I
get the
error.

class MyClass
{
       //Variables etc...
};

This is my implementation...

MyClass.mm

//Code...

I get the error in the header file. It says it cannot find iostream.
From what everyone has been saying it sounds like I am doing it
right so why do I get an error?


Phil.

On 8 Feb 2008, at 23:20, John Stiles wrote:


No. Headers stay headers. The code files that include the headers need to be .cpps or .mms.


Philip Bridson wrote:

OK thats cool. My #include <iostream> is in a .h file. Just to
clarify do I need to make the .h file a .mm?

Thanks.

On 8 Feb 2008, at 23:06, John Stiles wrote:


Any file that #includes <iostream>, either directly or indirectly via another header, needs to be a .cpp or .mm in order to work. .c or .m will not work.



Philip Bridson wrote:
Thanks both to Dave and John,

I am using .mm for my implementation files but it is in the .h
files i am having problems. Do I need to put the entire class,
including deceleration in an .mm file?

Thanks guys.

Phil

On Feb 8, 2008, at 2:51 PM, Philip Bridson wrote:



I am trying to write using Objective-C++. I have read the docs
and understand what I can and can't do with it but I have a
really basic problem. When I put #include <iostream> in my
header files I get an error saying that the file cannot be
found? Why is this?


Most likely because the compiler doesn't think that it's compiling an objective-c++ file, which means that it isn't using the C++ header search paths. What extension are you using for your filename? You have to use .mm to tell the compiler that it's objective-c++.



Also when creating the file, do I create a C++ file or an Obj-C
file or doesn't it matter?


It should be a .mm file.



Finally, I want to do some thing like this

#ifdef _MAC_OS_X
    //do some obj-c code
#endif

#ifdef _WIN32
    //use WIN32 API coding
#endif


#ifdef __OBJC__ //objc only stuff #endif



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at
cocoa-dev-admins(at)lists.apple.com


Help/Unsubscribe/Update your Subscription:
40gmail.com


This email sent to email@hidden






_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Objective-C++
      • From: "Herb Petschauer" <email@hidden>
References: 
 >Objective-C++ (From: Philip Bridson <email@hidden>)
 >Re: Objective-C++ (From: Philip Bridson <email@hidden>)
 >Re: Objective-C++ (From: John Stiles <email@hidden>)
 >Re: Objective-C++ (From: Philip Bridson <email@hidden>)
 >Re: Objective-C++ (From: John Stiles <email@hidden>)
 >Re: Objective-C++ (From: Philip Bridson <email@hidden>)
 >Re: Objective-C++ (From: "Herb Petschauer" <email@hidden>)
 >Re: Objective-C++ (From: "Herb Petschauer" <email@hidden>)
 >Re: Objective-C++ (From: Philip Bridson <email@hidden>)
 >Re: Objective-C++ (From: "Herb Petschauer" <email@hidden>)

  • Prev by Date: Re: Leopard and Tiger Notification Differences?
  • Next by Date: Re: Objective-C++
  • Previous by thread: Re: Objective-C++
  • Next by thread: Re: Objective-C++
  • Index(es):
    • Date
    • Thread