Topic: strange case (template class) for help
Author: ding@cis.njit.edu (Ding Jing)
Date: 6 May 93 18:14:43 GMT Raw View
extern "C" {
#include <string.h>
#include <stdio.h>
#include <ctype.h>
}
#include<iostream.h>
#include<strstream.h>
#include<stream.h>
typedef struct {
char context[10];
int id;
} StrIng;
template <class T>
class D {
char tname[10];
T* t;
public:
void insert(){
t=new T;
strcpy(tname,"T1");
t->insert("CT1");
//printf("strange staff happens\n");
(t+1)->insert("CT2");
}
void output(){
cout <<"tname::"<<tname<<"\n";
t->output();
(t+1)->output();
}
};
class C {
char cname[10];
int cid;
public:
C(){
strcpy(cname,"");
}
void insert(char name[10]){
strcpy(cname,name);
cid=2;
}
void output(){
cout <<"contain:"<<cname<<"\n";
}
};
int main (int argc,char* argv[])
{
C c;
D<C> d;
d.insert();
d.output();
}