• 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: C++ templates?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++ templates?


  • Subject: Re: C++ templates?
  • From: "David Piasecki" <email@hidden>
  • Date: Thu, 15 Apr 2004 13:21:55 -0700

I didn't even have to use the template. Simply creating one in
MyObject, as shown below again, will crash the program. I don't use any
objective-C objects with this template. See my previous e-mail for the
full template source. It's pretty simple. I think I created the
template correctly, though I could be wrong because I don't use
templates very often. I ended up creating the same MyMath object in a
non-template version, and it works fine, but I would like to be able to
use templates if I can.

Hmmm... I've always used templates that have the syntax <class Type>
instead of <typename Type> like you do. Could that be the problem?

#include "MyMath.h"

class MyObject {
public:
MyObject();
~MyObject();

MyMath<int> mathUtility; // this line causes the app to crash

private:
};

David



On Apr 15, 2004, at 12:28 PM, Allan Odgaard wrote:

> On 15. Apr 2004, at 20:04, David Piasecki wrote:
>
>> I tried creating a C++ template for my Cocoa application in XCode. It
>> compiles fine, but I get a runtime error which crashes my application,
>> even if all I do is create the object. Source included below...
>
> Correct me if I am wrong, but your code-snip did not show any usage of
> the template? Do you use ObjectiveC objects with this template? and
> what do you have to do at runtime to provoke the crash?
>
> That said, there does seem to be some template-related problems with
> ObjectiveC++ resulting in both compile-time (internal compiler error)
> and run-time problems. For the latter though my problem has so far
> been limited to calling ObjC methods in templated code, e.g. something
> like this:
>
> // main.mm
> #import <Cocoa/Cocoa.h>
>
> template <typename T> void dummy ()
> {
> [NSFont fontWithName:@"Monaco" size:12.0f];
> }
>
> int main (int argc, char const* argv[])
> {
> [NSAutoreleasePool new];
> dummy<int>();
> return 0;
> }
>
> Will crash (at runtime) with a segmentation error -- so generally I
> avoid having ObjC code in templated code :)
>
>
>
>
>
> ** Cocoa FAQ: <http://www.alastairs-place.net/cocoa/faq.txt> **
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: C++ templates?
      • From: Allan Odgaard <email@hidden>
References: 
 >C++ templates? (From: "David Piasecki" <email@hidden>)
 >Re: C++ templates? (From: Allan Odgaard <email@hidden>)

  • Prev by Date: Re: HotKey contains click
  • Next by Date: Re: Install Program for Completed App
  • Previous by thread: Re: C++ templates?
  • Next by thread: Re: C++ templates?
  • Index(es):
    • Date
    • Thread