생성자 (3) 썸네일형 리스트형 [C++]멤버 초기화 리스트를 사용 - 인자의 사용 12345678910111213141516171819202122232425262728293031323334353637383940414243 #include using namespace std; class NeedConstructor{public: const int maxCount; int& ref; int sample; NeedConstructor(); NeedConstructor(int count, int& number);// 두개의 인자가 있는 생성자 추가 }; NeedConstructor::NeedConstructor(int count, int& number)// 두개의 인자가 있는 생성자 추가 : maxCount(count), ref(number){ sample = 200;} NeedConstru.. [C++] 디폴트 생성자의 추가 1234567891011121314151617181920212223242526272829303132333435363738#include using namespace std; // Point 클래스를 정의한다.class Point{public: // 멤버 변수 int x, y; // 멤버 함수 void Print(); // 생성자 Point(); //생성자는 클래스와 동일한 이름을 가진 멤버 함수}; Point::Point(){ x = 0; y = 0;}void Point::Print(){ cout [JAVA] 생성자와 상속 1234567package a; public class ConstructorDemo { public static void main(String[] args) { ConstructorDemo c = new ConstructorDemo(); }}Colored by Color Scriptercs 위의 예제는 에러를 발생시키지 않는다. ConstructorDemo 객체를 생성할 때 자동으로 생성자를 만들어주기 때문이다 12345678package a; public class ConstructorDemo { public ConstructorDemo(int param1) {} public static void main(String[] args) { ConstructorDemo c = new ConstructorDe.. 이전 1 다음