Call to constructor function

Source: Internet
Author: User
Call to the constructor function
#define _crt_secure_no_warnings
#include <iostream>
#include <string>
using namespace std;
Class A
{public
:
	A () {a=1;}
	A (int a) {
		this->a=a;
	}
	void ShowA () {
		cout<<a<<endl;
	}
Protected:
private:
	int A;
};

int main (int args,const char * argv[])
{
	
	A a0 ();  function declaration, not creating object
	//a0.showa ();   Error

	A A1;//parameterless constructor calls without parentheses
	A1.showa ();

	A A2 (2); A parametric constructor
	A2.showa ();

	A a3=3;//has a parametric constructor and calls the transformation constructor
	A3.showa ();

	A a4= (1,2,3,4); A parameter constructor, which invokes the transformation constructor, uses the comma expression
	a4.showa ();

	A A5=a (5);  An anonymous object was created
	A5.showa ();

	cout<< "\n###################" <<endl;
	return 0;
}




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.