Re: C++ templates?
Re: C++ templates?
- Subject: Re: C++ templates?
- From: Dix Lorenz <email@hidden>
- Date: Fri, 16 Apr 2004 00:31:18 +0200
On 15.04.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...
David
Hi David,
I'll make a few assumptions:
This:
#include "MyMath.h"
class MyObject {
public:
MyObject();
~MyObject();
MyMath<int> mathUtility; // this line causes the app to crash
private:
};
is where you use the template?
This:
-----------------------------------------------
template <class T>
class MyMath {
public:
MyMath();
~MyMath();
T max( T a, T b );
T min( T a, T b );
private:
};
is your MyMath.h (or whatever) file?
and this:
--------------------------------------------------
#include "MyMath.h"
template <class T>
MyMath<T>::MyMath() { }
template <class T>
MyMath<T>::~MyMath() { }
template <class T>
T MyMath<T>::max( T a, T b ) {
if( a > b ) return a;
else return b;
}
template <class T>
T MyMath<T>::min( T a, T b ) {
if( a < b ) return a;
else return b;
}
is in MyMath.cpp (or any other .cpp-file)?
In that case: The implementations need to be available at compile-time,
which means you'll have to put all that stuff from MyMath.cpp directly
in the MyMath.h file. I also assume you have zerolink switched on
because otherwise the linker would complain before even starting your
app...
Greetings,
Dix
_______________________________________________
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.