Creative Code

main.cpp(컴파일러가 자동생성하는 함수) 본문

C++ Programming

main.cpp(컴파일러가 자동생성하는 함수)

빛하루 2023. 9. 1. 14:48

※main.cpp파일

#include <iostream>

#include "empty.h"



int main() {

	Empty e1;   //컴파일러에서 디폴트 생성자와 소멸자가 자동으로 생성)(명시적인 생성자가 없을때 생성)

	const Empty e2 = e1;  //컴파일러에서 복사생성자를 자동으로 생성

	

	e1 = e2;

	

	Empty *p1 = &e1;         // e1.operator&()

	const Empty *p2 = &e2;	   // e2.operator&()

	

	return 0;

}

※empty.h파일

#ifndef EMPTY_H

#define EMPTY_H





// 따로 만들지 않아도 컴파일러에서 자동으로 만들어주는 멤버함수

class Empty {

	//Empty() {       }; //클래스 안에서 함수를 정의할 수 있다 (inline 함수로 만들 때)

	//~Empty() {       };

	//Empty(const Empty& rhs) {/* memberwise copy */  };  //각각의 멤버들을 치환하는 복사생성자

	//Empty& operator=(const Empty& rhs) { /*memberwise copy */ }; //각각의 멤버들을 치환하는 연산함수

	//Empty* operator&() {return this;} ;

	//const Empty* operator&() const {return this;};

};



#endif

'C++ Programming' 카테고리의 다른 글

main.cpp(complex클래스 증감연산자)  (0) 2023.09.01
main.cpp(employee클래스)  (0) 2023.09.01
main.cpp(string2)  (0) 2023.09.01
main.cpp(string)  (0) 2023.08.31
main.cpp(rational클래스 여러 연산자)  (0) 2023.08.31