-
카테고리
-
세부 분야
프로그래밍 언어
-
해결 여부
미해결
m_i 값이 안바뀌는 이유가 뭔가요?
19.10.05 11:43 작성 조회수 213
1
//
// main.cpp
// inheritance_ex01
//
// Created by Kevin on 04/10/2019.
// Copyright © 2019 Kevin. All rights reserved.
//
#include <iostream>
using namespace std;
class Mother { // basic class
private:
int m_i;
public:
//Mother() {}
Mother(const int& i_in) : m_i(i_in) {
std::cout << "Mother constructor" << std::endl;
std::cout << "m_i " << m_i << std::endl;
}
void setValue(const int& i_in) {
std::cout << "i_in " << i_in << std::endl;
m_i = i_in;
std::cout << "m_i " << m_i << std::endl;
}
int getValue() {
return m_i;
}
};
class Child : public Mother {
private:
double m_d;
public:
Child(const int& i_in, const double& d_in) : Mother(i_in), m_d(d_in) {
std::cout << "Child constructor" << std::endl;
Mother::setValue(i_in);
}
void setValue(const int& i_in, const double& d_in) {
}
void setValue(const double& d_in) {
m_d = d_in;
}
double getValue() {
return m_d;
}
}; // derived class
int main(int argc, const char * argv[]) {
Mother mother(512);
std::cout << mother.getValue() << std::endl;
Child child(1024, 2048);
std::cout << "m_i value : " << mother.getValue() << std::endl;
// 왜 512인가요?
std::cout << "m_d value : " << child.getValue() << std::endl;
return 0;
}
답변을 작성해보세요.
답변 4