Topic: help
Author: escobar@archimedes.chinalake.navy.mil (Fernando Escobar)
Date: Fri, 30 Sep 1994 17:00:48 GMT Raw View
Does anyone know where could i find an implementation of a SET, or a
DICTIONARY out there? I am working on a project and would like to use these as an
example.
Thank you.
Fernando J. Escobar
escobar@archimedes.chinalake.navy.mil
Author: ding@cis.njit.edu (Ding Jing)
Date: 9 May 93 20:34:24 GMT Raw View
Newsgroups: comp.std.c++
Subject: strange case (template class) for help
Summary:
Expires:May 15,93
Sender: Michael J. Ding
Followup-To:
Distribution: comp.std.c++
Organization: New Jersey Institute of Technology
Keywords: help
hi,everybody,
sorry to re-post this question because I found my question was cut in last time
----------------------------------------------------------------------------
I am a new comer to use "template",I have a strange case in the following code:
extern "C" {
#include <string.h>
#include <stdio.h>
#include <ctype.h>
}
#include<iostream.h>
#include<strstream.h>
#include<stream.h>
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");
/* This stmt made different output i,if I comment this stmt the output is
wrong (see case 1),otherwise it output what I need.(case 2) Why?
case1 (wrong answer)
tname::T1
contain:CT1
contain:
case2 (correct answer)
tname::T1
contain:CT1
contain:CT2
strastaff happens */
(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();
}
Thank you advance
Michael J. Ding