Created
March 26, 2020 12:00
-
-
Save wnoise/93f7eba2974df899b7928982b2da0b10 to your computer and use it in GitHub Desktop.
This file contains 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
#include <iostream> | |
#include <string> | |
struct base | |
{ | |
virtual ssize_t write(const char *buf, size_t buf_len); | |
ssize_t write(std::string &s); | |
}; | |
ssize_t base::write(const char *buf, size_t buf_len) | |
{ | |
std::cout << "base::write(char *)" << std::endl; | |
} | |
ssize_t base::write(std::string &s) | |
{ | |
std::cout << "base::write(string)" << std::endl; | |
return write(s.data(), s.size()); | |
} | |
struct derived : base | |
{ | |
using base::write; | |
virtual ssize_t write(const char *buf, size_t buf_len); | |
}; | |
ssize_t derived::write(const char *buf, size_t buf_len) | |
{ | |
std::cout << "derived::write(char *)" << std::endl; | |
} | |
int main() | |
{ | |
std::string s; | |
base b; | |
derived d; | |
b.write("", 0); | |
b.write(s); | |
d.write("", 0); | |
d.write(s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment