Template bug?
Jarrett Billingsley
kb3ctd2 at yahoo.com
Tue Jan 30 06:54:47 PST 2007
"Artyom Shalkhakov" <artyom.sh at gmail.ru> wrote in message
news:epmlh5$2crr$1 at digitaldaemon.com...
> Okay, I've tried to use pointer to class because I intend to use this
> template for both structures and classes. How do I do that? Do I have to
> write template specialization?
Yep. You can do something like:
struct temp_t( type : Object ) {
void setOwner( type newOwner ) {
owner = newOwner;
}
type getOwner() {
return owner;
}
protected {
temp_t * head;
temp_t * next;
temp_t * prev;
type owner;
}
}
struct temp_t( type ) {
void setOwner( type *newOwner ) {
owner = newOwner;
}
type *getOwner() {
return owner;
}
protected {
temp_t * head;
temp_t * next;
temp_t * prev;
type * owner;
}
}
So it'll use the non-pointer version for classes (i.e. anything that derives
from Object), and the pointer version for everything else.
More information about the Digitalmars-d-learn
mailing list