|

楼主 |
发表于 2008-5-21 20:21:00
|
显示全部楼层
Re: 请问多线程(MT)和多线程调试(MTd)的区别
//testdll.cpp:
#include "testdll.h"
#ifdef DLL
testclass::testclass()
{
t=NULL;
}
testclass::testclass(char* t__)
{
if(!t__)
{
t=NULL;return;
}
t=new char[strlen(t__)+1];
strcpy(t,t__);
return;
}
testclass::~testclass()
{
if(!t)return;
delete t;
t=NULL;
}
testdll::testdll(void)
{
tpvpi=new std::vector<testclass*>();
tpvpi->clear();
}
testdll::testdll(testclass* cpi)
{
tpvpi=new std::vector<testclass*>();
testclass* tcpi=cpi;
tpvpi->clear();
tpvpi->push_back(tcpi);
}
testdll::~testdll(void)
{
if(!tpvpi)return;
for(unsigned long i=0;i<tpvpi->size();i++)
delete (*tpvpi);
tpvpi->clear();
delete tpvpi;
}
testdll2::testdll2(void)
{
tpvpi=new std::vector<int*>();
tpvpi->clear();
}
testdll2::testdll2(int* cpi)
{
tpvpi=new std::vector<int*>();
tpvpi->clear();
tpvpi->push_back(cpi);
}
testdll2::~testdll2(void)
{
if(!tpvpi)return;
for(unsigned long i=0;i<tpvpi->size();i++)
delete (*tpvpi);
tpvpi->clear();
delete tpvpi;
}
testdll3::testdll3(void)
{
tpvpi.clear();
}
testdll3::testdll3(int* cpi)
{
tpvpi.clear();
tpvpi.push_back(cpi);
}
testdll3::~testdll3(void)
{
for(unsigned long i=0;i<tpvpi.size();i++)
delete (tpvpi);
tpvpi.clear();
}
testdll4::testdll4(void)
{
tpvpi.clear();
}
testdll4::testdll4(int* cpi)
{
tpvpi.clear();
tpvpi.push_back(*cpi);
}
testdll4::~testdll4(void)
{
tpvpi.clear();
}
testdll5::testdll5(void)
{
tpvpi.clear();
}
testdll5::testdll5(int cpi)
{
tpvpi.clear();
tpvpi.push_back(cpi);
}
testdll5::~testdll5(void)
{
tpvpi.clear();
}
testdll6::testdll6(void)
{
ttpi=NULL;
}
testdll6::testdll6(int* cpi)
{
ttpi=new int;
*ttpi=*cpi;
}
testdll6::~testdll6(void)
{
delete ttpi;
}
#else
#pragma comment(lib,"testdll.lib")
int _tmain(int argc, char* argv[])
{
//*
testclass* tpi=new testclass("abcd");
testdll* pt=new testdll(tpi);
printf("%d\n",pt->tpvpi->size());
if(pt->tpvpi->size()>0)
{
printf((*(pt->tpvpi))[0]->t);
printf("\n");
}
//*/
int* tpi2=new int;
*tpi2=4;
//*
testdll2* pt2=new testdll2(tpi2);
printf("%d\n",pt2->tpvpi->size());
testdll3* pt3=new testdll3(tpi2);
printf("%d\n",(pt3->tpvpi).size());
testdll4* pt4=new testdll4(tpi2);
printf("%d\n",(pt4->tpvpi).size());
testdll5* pt5=new testdll5(*tpi2);
printf("%d\n",(pt5->tpvpi).size());
//*/
testdll6* pt6=new testdll6(tpi2);
printf("%d\n",*(pt6->ttpi));
return 1;
}
#endif
//虽然有了结论,但我还不知道在运行时阶段2者有什么区别。。。请教高手
|
|