Objective-C++

  • Hi there,

    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?

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

    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

    Does anyone know how to do this? Is the above correct?

    Many thanks for your help.

    Phil.
  • Philip Bridson wrote:
    > Hi there,
    >
    > 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?
    >
    Rename the file extension from .c or .m to .mm and try again.

    > Also when creating the file, do I create a C++ file or an Obj-C file
    > or doesn't it matter?
    Neither is right, you want a .mm file. You might need to rename it by
    hand if that isn't an option.

    > 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
    >
    > Does anyone know how to do this? Is the above correct?
    >
    Use #if __APPLE__

    > Many thanks for your help.
    >
    > 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

    --
    Dave Carrigan
    <dave...>
    Seattle, WA, USA
  • 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

    --
    Dave Carrigan
    <dave...>
    Seattle, WA, USA

    On 8 Feb 2008, at 22:56, John Stiles wrote:

    > Philip Bridson wrote:
    >> Hi there,
    >>
    >> 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?
    >>
    > Rename the file extension from .c or .m to .mm and try again.
    >
    >> Also when creating the file, do I create a C++ file or an Obj-C
    >> file or doesn't it matter?
    > Neither is right, you want a .mm file. You might need to rename it
    > by hand if that isn't an option.
    >
    >> 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
    >>
    >> Does anyone know how to do this? Is the above correct?
    >>
    > Use #if __APPLE__
    >
    >
    >> Many thanks for your help.
    >>
    >> Phil.
  • 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
    >
  • Also, if you're doing cross-platform work, you might think about using
    the Abstract Factory design pattern for abstracting out OS details to
    a generic interface.  You can even put the declaration of the ObjC
    class in the .mm and maintain a pure C++ header file for use elsewhere
    in your code.

    wes

    On Feb 8, 2008 3:06 PM, John Stiles <JStiles...> 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
    >>

    >
  • 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
    >>
  • #ifdef __cplusplus
    #include <iostream>
    #endif

    [I fight this all the time :-)]

    Cheers,
    -H.

    On 08/02/2008, Philip Bridson <philipleebridson...> 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
    >>>

    >
  • 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
    >>>>
    >>
  • --- Philip Bridson <philipleebridson...> 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?

    No, because the header isn't directly compiled. But
    any file that IS compiled that includes that header
    needs to be .cpp or .mm.

    Cheers,
    Chuck

          ____________________________________________________________________________________
    Be a better friend, newshound, and
    know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
  • Seriously, add the #ifdef __cplusplus from my previous response :-)

    On 08/02/2008, Philip Bridson <philipleebridson...> 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
    >>>>>
    >>>

    >
  • 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 <philipleebridson...> 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 <philipleebridson...> 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
    >
    >
    >
  • 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 <philipleebridson...> 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 <philipleebridson...> 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
    >>
    >>
    >>
  • 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 <philipleebridson...> 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 <philipleebridson...> 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 <philipleebridson...> 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
    >>>
    >>>
    >>>
    >
    >
  • 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 <philipleebridson...> 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 <philipleebridson...> 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 <philipleebridson...> 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
    >>>>
    >>>>
    >>>>
    >>
    >>
  • Depends on what you are doing.  If you are actually writing a Cocoa
    App then why not create a new Cocoa App?  You get a default nib, etc.
    for free.  Just create new files with .mm.

    Cheers,
    -H.

    On 08/02/2008, Philip Bridson <philipleebridson...> wrote:
    > 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 <philipleebridson...> 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 <philipleebridson...> 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 <philipleebridson...> 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
    >>>>>
    >>>>>
    >>>>>
    >>>
    >>>
    >
    >
  • Thank you. That was very helpful.

    Phil

    On 9 Feb 2008, at 00:04, Herb Petschauer wrote:

    > Depends on what you are doing.  If you are actually writing a Cocoa
    > App then why not create a new Cocoa App?  You get a default nib, etc.
    > for free.  Just create new files with .mm.
    >
    > Cheers,
    > -H.
    >
    > On 08/02/2008, Philip Bridson <philipleebridson...> wrote:
    >> 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 <philipleebridson...> 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 <philipleebridson...> 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 <philipleebridson...> 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
    >>>>>>
    >>>>>>
    >>>>>>
    >>>>
    >>>>
    >>
    >>
  • Am 09.02.2008 um 01:04 schrieb Herb Petschauer:

    > Depends on what you are doing.  If you are actually writing a Cocoa
    > App then why not create a new Cocoa App?  You get a default nib, etc.
    > for free.  Just create new files with .mm.

    In case this is not immediately obvious - if you choose a template
    from Xcode's "New File..." asisstant, you can rename the file to end
    with .mm right there.

    BTW: I found it easier to have _all_ my Objective-C files have .mm
    extensions. Most of our code does reference a C++ class or the other
    and even for pure Objective-C code having it compiled as Objective-C++
    usually doesn't hurt (unless you compile against a library that
    doesn't have C++-savvy header files).
    By making all my files Objective-C++, I avoid these 10 minutes of
    confusion until I discover that the only reason the compiler complains
    about some apparently well-formed C++ header file is because it's
    compiling in plain-C mode ;-)

    </jum>
  • We did a photoshop plugin at my day job using Objective C++. We
    started the project by creating a Cocoa Plug-in then just changed the
    file names to .mm and made sure we always created the names with .mm.

    One other good thing to do, at least it was for us, was to write
    objective C wrappers around C++ code hiding C++ strings and such. Alot
    of the Objectve C code were operations on the C++ object not a one for
    one all ratio. Just made our life easier and the C++ wasn't scattered
    through out the code.

    Scott

    On Feb 11, 2008, at 8:52 AM, Jens Miltner wrote:

    >
    > Am 09.02.2008 um 01:04 schrieb Herb Petschauer:
    >
    >> Depends on what you are doing.  If you are actually writing a Cocoa
    >> App then why not create a new Cocoa App?  You get a default nib, etc.
    >> for free.  Just create new files with .mm.
    >
    > In case this is not immediately obvious - if you choose a template
    > from Xcode's "New File..." asisstant, you can rename the file to end
    > with .mm right there.
    >
    > BTW: I found it easier to have _all_ my Objective-C files have .mm
    > extensions. Most of our code does reference a C++ class or the other
    > and even for pure Objective-C code having it compiled as Objective-C+
    > + usually doesn't hurt (unless you compile against a library that
    > doesn't have C++-savvy header files).
    > By making all my files Objective-C++, I avoid these 10 minutes of
    > confusion until I discover that the only reason the compiler
    > complains about some apparently well-formed C++ header file is
    > because it's compiling in plain-C mode ;-)
    >
    > </jum
  • On 2/11/08 5:52 PM, Jens Miltner said:

    > BTW: I found it easier to have _all_ my Objective-C files have .mm
    > extensions.

    Be warned however that Xcode 3's new 'refactoring' feature does not
    support Obj-C++.  So if you have .mm's, no refactoring for you! :(

    --
    ____________________________________________________________
    Sean McBride, B. Eng                <sean...>
    Rogue Research                        www.rogue-research.com
    Mac Software Developer              Montréal, Québec, Canada
  • Il giorno 11/feb/08, alle ore 19:34, Sean McBride ha scritto:

    > On 2/11/08 5:52 PM, Jens Miltner said:
    >
    >> BTW: I found it easier to have _all_ my Objective-C files have .mm
    >> extensions.
    >
    > Be warned however that Xcode 3's new 'refactoring' feature does not
    > support Obj-C++.  So if you have .mm's, no refactoring for you! :(
    >

    I usually set the "Compile Sources As" project option to "Objective-C+
    +" instead of bothering to rename all the files to .mm

    As a bonus, the refactoring functions are still there (although the
    only time I dared to try one of them, Xcode crashed and burned
    <sigh> ;-)

    --
    Simone Tellini
    http://tellini.info
  • I guess for me .mm is a very visual. You know its objective C++. Just
    like .cpp is cplusplus. I don't expect C++ code in a .c file.

    Scott

    On Feb 11, 2008, at 10:42 AM, Simone Tellini wrote:

    >
    > Il giorno 11/feb/08, alle ore 19:34, Sean McBride ha scritto:
    >
    >> On 2/11/08 5:52 PM, Jens Miltner said:
    >>
    >>> BTW: I found it easier to have _all_ my Objective-C files have .mm
    >>> extensions.
    >>
    >> Be warned however that Xcode 3's new 'refactoring' feature does not
    >> support Obj-C++.  So if you have .mm's, no refactoring for you! :(
    >>
    >
    > I usually set the "Compile Sources As" project option to "Objective-C
    > ++" instead of bothering to rename all the files to .mm
    >
    > As a bonus, the refactoring functions are still there (although the
    > only time I dared to try one of them, Xcode crashed and burned
    > <sigh> ;-)
    >
    > --
    > Simone Tellini
    > http://tellini.info
  • Am 11.02.2008 um 19:34 schrieb Sean McBride:

    > On 2/11/08 5:52 PM, Jens Miltner said:
    >
    >> BTW: I found it easier to have _all_ my Objective-C files have .mm
    >> extensions.
    >
    > Be warned however that Xcode 3's new 'refactoring' feature does not
    > support Obj-C++.  So if you have .mm's, no refactoring for you! :(

    Yes, unfortunately, I already found out about this when I would have
    had a need for some refactoring help :(

    Am 11.02.2008 um 19:41 schrieb Simone Tellini:

    > I usually set the "Compile Sources As" project option to "Objective-C
    > ++" instead of bothering to rename all the files to .mm
    >
    > As a bonus, the refactoring functions are still there (although the
    > only time I dared to try one of them, Xcode crashed and burned
    > <sigh> ;-)

    Ah - I didn't know refactoring would work when keeping the suffix.
    Although, according to your experience, it may not really work at all
    with C++ code and by keeping the extension .m it may think it's plain
    C/Objective-C code, thus failing to properly factor?

    And yes, I have already filed a request to support refactoring for C+
    + / Objective-C++ code ;-)

    </jum>
  • On 11.02.2008, at 18:06, Scott Andrew wrote:
    > We did a photoshop plugin at my day job using Objective C++. We
    > started the project by creating a Cocoa Plug-in then just changed
    > the file names to .mm and made sure we always created the names
    > with .mm.

      IMHO it helps code organization (especially for cross-platform code)
    if you try to keep C++, ObjC and ObjC++ separate. It means that all
    your Mac-specific code is ObjC, all your platform-neutral code is C++,
    and the glue between them is easily distinguishable because it's ObjC+
    +. Makes it easier to avoid that anyone introduces code that may break
    the other platforms.

    On 11.02.2008, at 19:42, Simone Tellini wrote:
    > I usually set the "Compile Sources As" project option to "Objective-C
    > ++" instead of bothering to rename all the files to .mm

      I've had problems with this. There are subtle differences between
    how C and C++ interpret the same (C-) statements. So, if you have to
    keep using other peoples' C code and need to update it when they do,
    if you do this compiler switch, you will suddenly get oodles of wrong
    warnings from the C++ compiler, and on rare occasions even errors or
    crashes. So, I like to compile everything the way it was specified as
    its suffix, and if I have code that expects to be run through a C++
    compiler, is external and has .c suffixes, I put them in a separate
    project.

    Cheers,
    -- Uli Kusterer
    "The Witnesses of TeachText are everywhere..."
    http://www.zathras.de
  • On 11.02.2008, at 19:52, Scott Andrew wrote:

    > I guess for me .mm is a very visual. You know its objective C++.
    > Just like .cpp is cplusplus. I don't expect C++ code in a .c file.
    >

    On IRIX there was a C++ make rule for .C (in contrary to .c) ;-)
  • On 13.02.2008, at 11:09, Thomas Engelmeier wrote:
    > On IRIX there was a C++ make rule for .C (in contrary to .c) ;-)

      I guess it's the same distinction as between .m and .M. The latter
    is not equivalent to the former, but rather to .mm.

    Cheers,
    -- Uli Kusterer
    "The Witnesses of TeachText are everywhere..."
    http://www.zathras.de
previous month february 2008 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29    
Go to today
MindNode
MindNode offered a free license !