current position:Home>C + + parameterless constructor (difference between stack and heap)
C + + parameterless constructor (difference between stack and heap)
2022-05-15 05:09:44【Junmo vv】
1. Custom type
#include <iostream>
using namespace std;
class Test
{
public:
Test() {
cout << "T constructor" << endl;
}
~Test() {
cout << "T destructor" << endl;
}
};
Test t2()
{
Test *p3 = new Test;
cout << "t2 function" << endl;
return *p3;
}
int main()
{
cout << "heap" << endl; // Heap objects The nonparametric structure of function 2 Anyone can
Test *p = new Test();
delete p;
p = nullptr;
Test *p2 = new Test;
delete p2;
p2 = nullptr;
cout << endl;
cout << "stack" << endl;
Test t1;
cout << "t1 end" << endl;
Test t2(); // At this point, the bracketed Just made a statement The return value of the function is a Test The object of , The function name is t2 ps: Generally speaking, it is written to other files Then declare here , At this time, only demo
t2();
cout << "t2 end" << endl;
return 0;
}
therefore Test t2() Will not be considered a parameterless constructor , Just function declaration , Otherwise there will be ambiguity
2. The base type
new Will only apply for space , After adding parentheses, it will be initialized to 0( Maybe some compilers It will be optimized to 0, But we still need to add it ourselves , Don't rely on the compiler )
copyright notice
author[Junmo vv],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/135/202205142225592913.html
The sidebar is recommended
- babel7. 0 compatible with IE browser
- Nginx configuring reactrouter browserhistory browserrouter
- JS, react use html2canvas page screenshot and export
- Big data front-end visualization screen -- the road of front-end development
- [a quick introduction and comparison of multiple languages -- JavaScript, typescript, python, golang, trust, Java, ruby]
- Vue element admin login function, token filling, language conversion, routing setting
- Summation of corresponding position elements of multiple lists in Python
- Discussion on HTML page knowledge
- Using Ajax to realize non refresh paging
- HTTP format
guess what you like
Zhang San has a meal - did he eat the difference between get and post in HTTP?
The ultimate actual combat of the most complete tourism project based on spring boot + Vue front-end and back-end separation in history (with source code attached), none of them!!!
Vue basic grammar
LeetCode 217. There are duplicate elements
Pagoda does not configure the solution of SSL site accessing HTTPS and jumping to other websites
Vue3 isProxy
About the problem that the container will hang up after starting nginx in the docker container
Introduction to JavaScript
The core element of large-scale software design is to control complexity. What is the root cause?
What are the core elements of large-scale software design?
Random recommended
- C + + small job - create an array class arr to delete duplicate elements in the array
- Fancy front gradient
- Understanding of this in JavaScript
- Introduction to HTML + CSS Basics
- JavaScript makes a simple "aircraft war"
- Summary of Vue basics 14: what does vuex do?
- CSS introduction
- CSS introduction method
- CSS basic selector
- HTTPS pressure test you don't know
- Intersectionobserver and custom hooks
- Vue uses vis to implement topology map
- [Django CI system] if the front-end date is complete, it will be fully updated to the back-end; If the front-end date is incomplete, the date will not be updated to the back-end-20220510
- Is your endurance anxiety saved? 10 minute full electric vehicle technology is mature, netizen: it's useless to find a charging pile
- After reading 2000 applications for venture capital financing, I summed up the 20 elements that investors value most
- Diesel automobile double pickup truck leads the industry, and Jiangxi Isuzu no longer bows its head and acts recklessly
- Vue + elementui learning notes, use custom events to monitor the closing and opening events of the pop-up window of the introduced component
- Lazy loading usage based on element UI tree directory
- Vue encapsulates multiple request requests (solution for multiple domain names)
- Getting started with Vue
- Vuex getting started from 0 to 1
- Uniapp configuration element UI code block
- HTTP request method security: get, post, put, patch, delete, options, head, trace
- Axios source code analysis - Request interceptor
- Introduction to HTML tag list
- JavaScript output data
- JavaScript comments
- javascript Variables
- Introduction to JavaScript
- HTML and servlet cannot be connected together, and the set servlet cannot be implemented
- The back end returns HTML code. How can the front end preview
- About vue3 0 failed to load SVG through SVG sprite loader
- Antd Vue realizes login login page layout - with verification code verification function - Case
- Find a 5 respectively × 5 the sum of all rows, columns and elements on two diagonal lines of the matrix. (the input data is inconsistent with the output data)
- Raptor flowchart: random function generates a random array. The size of array elements is in the closed range of 100-999 and the length is 10. Find out the largest element and display its position
- How does PHP render some of the following JSON data into HTML
- The requested resource is not available when idea runs the HTML file
- JMeter generates HTML test report
- The spring of Huidong white potted pearl is a restless dream
- Vue3, complex watch implementation, solution For the second time