Last active
January 6, 2021 00:44
-
-
Save Shaun289/b90069632eec26b50e63770fa532a065 to your computer and use it in GitHub Desktop.
c++ override and overload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Parent { | |
public: | |
virtual void func(); | |
virtual void func(int32_t val); | |
}; | |
class Child:Parent { | |
public: | |
virtual void func(); | |
virtual void func(int32_t val); | |
}; | |
void Parent::func() { | |
std::cout << "Parent::func()" << std::endl; | |
// Child 객체가 호출한 경우 이 메소드는 | |
// Parent::func(int32_t) 와 Child::func(int32_t) 중 어떤 메소드를 부를까? | |
func(0); | |
} | |
void Parent::func(int32_t val) { | |
std::cout << "Parent::func(int32_t val)" << std::endl; | |
} | |
void Child::func() { | |
Parent::func(); | |
std::cout << "Child::func()" << std::endl; | |
} | |
void Child::func(int32_t val) { | |
Parent::func(val); | |
std::cout << "Child::func(int32_t val)" << std::endl; | |
} | |
int main() | |
{ | |
//test(); | |
Child child; | |
child.func(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment