Dynamic creation and destruction of classes and lists, new, delete,clear

Source: Internet
Author: User

/*************************************************** Construction, deconstruction new, delete, List, list.clear ()  Version 1.0.8, May 10th, Copyright (C) 2015-2016 Acheld CHEN This software be provided ' as-is ', without any express  or implied warranty.  In no event would the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:1. The origin of this software must not being Misreprese nted You must not claim that wrote the original software. If software in a product, an acknowledgment in the product documentation would be appreciated  Not required. 2. Altered source versions must be plainly marked as such, and must is misrepresented as being the original Softwa  Teh 3. This notice is removed or altered from any source disTribution. Acheld CHEN Http://blog.csdn.net/acheld ****************************************************//////////////////o Ther CPP file call the Target function///////////////void Cxcontainertestdlg::onbnclickedbutton1 () {//Todo:extern xcontainermgr* thexcontainermgr;if (!thexcontainermgr) {thexcontainermgr = new xcontainermgr ();} Thexcontainermgr->run ();D Word Oldtick = GetTickCount (); while (TRUE) {DWORD Curtick = GetTickCount ();D word differ = Curtick-oldtick;if (differ > +) {if (thexcontainermgr) {Delete thexcontainermgr;thexcontainermgr = Null;return;}}} Xcontainermgr.h#pragma once#include "XContainer.h" Class Xcontainermgr{public:xcontainermgr (void), ~xcontainermgr (void);p ublic:void Init (), void Run ();p rotected: Xcontainer* M_pxcontainer;}; extern xcontainermgr* thexcontainermgr;///////////////////////xcontainermgr.cpp/////////////////////#include " StdAfx.h "#include" XContainerMgr.h "Xcontainermgr::xcontainermgr (vOID) {m_pxcontainer = NULL;} Xcontainermgr::~xcontainermgr (void) {if (m_pxcontainer) {Delete M_pxcontainer;m_pxcontainer = NULL;}} void Xcontainermgr::init () {if (!m_pxcontainer) {m_pxcontainer = new XContainer ();}} void Xcontainermgr::run () {Init ();} /****************************************************///xcontainer.h#pragma once#include "XContainerInterface.h" #include "XContainerInstance.h" #include "TagDef.h" class Xcontainer{public:xcontainer (void); ~xcontainer (void); void Init (); void Run ();p rotected:xcontainerinterface* m_pxcontainerinterface; xcontainerinstance* m_pxcontainerinstance;strdataasmlist m_dataasmlist;};/ xcontainer.cpp/////////////////////#include "StdAfx.h" #include "XContainer.h" XContainer:: XContainer (void) {m_pxcontainerinterface = Null;m_pxcontainerinstance = Null;init ();} Xcontainer::~xcontainer (void) {if (m_pxcontainerinterface) {Delete M_pxcontainerinterface;m_pxcontainerinterface = NULL;} if (m_pxcontainerinstance) {Delete M_pxcontainerinstance;m_pxcontainerinstance = NULL;} Strdataasmlistiter aiter = M_dataasmlist.begin (); for (; Aiter! = M_dataasmlist.end (); aiter++) {Lpstrdataasm PASM = *aiter if (PASM) {if (pasm->name) {delete [] pasm->name;pasm->name = NULL;} Delete pasm;pasm = NULL;}} BOOL Bempty = M_dataasmlist.empty (); if (!bempty) {m_dataasmlist.clear ();}} void Xcontainer::init () {if (!m_pxcontainerinterface) {m_pxcontainerinterface = new xcontainerinterface ();} if (!m_pxcontainerinstance) {m_pxcontainerinstance = new xcontainerinstance ();} for (int m =0; M <3; m++) {lpstrdataasm pData = new Strdataasm ();pD ata->id = m+1;strcpy (Pdata->name, "dataasm");pD Ata->score + = 0.03*m;m_dataasmlist.push_back (PData);}} void Xcontainer::run () {}/****************************************************///xcontainerinterface.h#pragma Once#include "XContainerInstance.h" class xcontainerinterface{public:xcontainerinterface (void); ~ Xcontainerinterface (void), void Init (), void Run ();p rotected:xcontainerinstance* m_pxcontainerinstance;};/ /////////////////xcontainerinterface.cpp/////////////////////#include "StdAfx.h" #include "XContainerInterface.h" Xcontainerinterface::xcontainerinterface (void) {m_pxcontainerinstance =null;init ();} Xcontainerinterface::~xcontainerinterface (void) {if (m_pxcontainerinstance) {Delete m_pxcontainerinstance;m_ Pxcontainerinstance = NULL;}} void Xcontainerinterface::init () {if (!m_pxcontainerinstance) {m_pxcontainerinstance = new xcontainerinstance ();}} void Xcontainerinterface::run () {}/****************************************************///xcontainerinstance.h# pragma once#include "tagDef.h" class xcontainerinstance{public:xcontainerinstance (void); ~xcontainerinstance (void); void Init (), void Run ();p rotected:strdataasmlist m_dataasmlist;};/ xcontainerinstance.cpp/////////////////////#include "StdAfx.h" #include " XContainerInstance.h "xcontainerinstance::xcontainerinstance (void) {Init ();} Xcontainerinstance::~xcontainerinstance (void) {Strdataasmlistiter aiter = M_dataasmlist.begin (); for (; Aiter! = M_dataasmlist.end (); aiter++) {Lpstrdataasm pAsm = *aiter;if (PASM) {if (pasm->name) {delete [] pasm->name;pasm->name = NULL;} Delete pasm;pasm = NULL;}} BOOL Bempty = M_dataasmlist.empty (); if (!bempty) {m_dataasmlist.clear ();}} void Xcontainerinstance::init () {for (int m =0; M <3; m++) {lpstrdataasm pData = new Strdataasm ();pD ata->id = m+1;strc PY (pdata->name, "instanceasm");pD Ata->score + = 0.03*m;m_dataasmlist.push_back (PData);}} void Xcontainerinstance::run () {}/****************************************************///tagdef.h#pragma once# Include <list> #include <vector>typedef struct tagstrdataasm{int id;char* name;float score;tagstrdataasm () {id = -1;name = new char[128];strcpy (name, "Asm"); score = 0.98;}} Strdataasm,*lpstrdataasm;typedef std::list<lpstrdataasm> strdataasmlist;typedef StrDataAsmList::iterator strdataasmlistiter;///////////////////////

Dynamic creation and destruction of classes and lists, new, delete,clear

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.