C + + pointer essay 1

Source: Internet
Author: User

#include "stdafx.h"
#include <iostream>
#include <map>
using namespace Std;
Using Std::map;

Class CA;
typedef map<int,ca*> MAP;


Class CA {
Public
int A;
};

int _tmain (int argc, _tchar* argv[])
{
Map map;
for (int i=0;i<2;i++)
{
ca* PA = new CA;
Pa->a = 1;
Map[i] = PA;
}

Map::iterator it = Map.begin ();
while (It! = Map.end ())
{
ca* PA = it->second;
Delete PA;
PA = NULL; The PA address asks NULL, but the address of the It->second is not NULL, so if there is no erase, the following sentence should be opened in strict sense, so as to avoid the use of empty values within the map.
It->second = NULL;
it + +;
}


it = Map.begin ();
while (It! = Map.end ())
{
ca* PA = it->second;
int a = 0;
it + +;
}

return 0;
}


/*
Here is a review of some of the concepts of C + +:
*PA is the data on the address indicated by the pointer PA.
The PA is the address that the pointer refers to, which is why Pa=null,it->second is not NULL
&AMP;PA represents the address of the pointer
*/

C + + pointer essay 1

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.