Skip to content

Instantly share code, notes, and snippets.

@phucnguyenv
Last active May 20, 2022 16:29
Show Gist options
  • Select an option

  • Save phucnguyenv/d0cdb273234e612816a23e55bfc38f11 to your computer and use it in GitHub Desktop.

Select an option

Save phucnguyenv/d0cdb273234e612816a23e55bfc38f11 to your computer and use it in GitHub Desktop.
C++ testbed
#include <iostream>
/* implementing virtual functions */
class B
{
public:
B() { f1(); }
/* compilers typically number the virtual functions in the order
in which they're declared */
virtual ~B() {}
virtual void f1() { f3(10); };
virtual int f2(char c) const {}
virtual void f3(int x) = 0;
void f4() const {}
};
class C : public B
{
public:
C() {}
~C(){}
virtual void f1() { std::cout << "f1" << std::endl; };
virtual int f2(char c) const {std::cout << "f2" << std::endl;};
virtual void f3(int x) { std::cout << "f3" << std::endl; };
void f4() const {std::cout << "f4" << std::endl;}
};
int main(int argc, char const *argv[])
{
C c;
auto hello = []() { std::cout << "Hell, world!" << std::endl; };
hello();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment