Skip to content

Instantly share code, notes, and snippets.

@wnoise
Created March 26, 2020 12:00
Show Gist options
  • Save wnoise/93f7eba2974df899b7928982b2da0b10 to your computer and use it in GitHub Desktop.
Save wnoise/93f7eba2974df899b7928982b2da0b10 to your computer and use it in GitHub Desktop.
#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