Skip to content

Instantly share code, notes, and snippets.

@xaizek
Created December 27, 2017 10:18
Show Gist options
  • Save xaizek/8d0407d5fb8ced3145188dce24938788 to your computer and use it in GitHub Desktop.
Save xaizek/8d0407d5fb8ced3145188dce24938788 to your computer and use it in GitHub Desktop.
Class method clash
#include "header.hpp"
#include <iostream>
class B : public A
{
void f()
{
doIt();
}
static void doIt()
{
std::cout << "first" << std::endl;
}
};
A *makeA1()
{
return new B();
}
#ifndef HEADER_HPP__
#define HEADER_HPP__
class A
{
public:
virtual void f() = 0;
};
A *makeA1();
A *makeA2();
#endif // HEADER_HPP__
#include "header.hpp"
#include <iostream>
int
main(int argc, char *argv[])
{
std::cout << "A1:" << std::endl;
makeA1()->f();
std::cout << "A2:" << std::endl;
makeA2()->f();
return 0;
}
#include "header.hpp"
#include <iostream>
class B : public A
{
void f()
{
doIt();
}
static void doIt()
{
std::cout << "second" << std::endl;
}
};
A *makeA2()
{
return new B();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment