Skip to content

Instantly share code, notes, and snippets.

@davamix
Last active January 2, 2018 02:08
Show Gist options
  • Save davamix/ba58aff527d4e2e012530672dd5a6a84 to your computer and use it in GitHub Desktop.
Save davamix/ba58aff527d4e2e012530672dd5a6a84 to your computer and use it in GitHub Desktop.
Is possible to move the implementation of Run function from Derived.h to Derived.cpp?
#include "IBase.h"
#include "Derived.h"
int main(){
Derived d;
d.Run();
}
#include <iostream>
#include "IBase.h"
#include "Derived.h"
void Derived::IBase::Run(){
std::cout << "Hello from derived" << std::endl;
}
#ifndef DERIVED_H
#define DERIVED_H
#include <iostream>
class Derived : public IBase{
public:
// void Run(){
// std::cout << "Hello from derived" << std::endl;
// }
~Derived(){}
void Run();
};
#endif
/tmp/cckxMhvH.o: In function `main':
abstract.cpp:(.text+0x19): undefined reference to `vtable for Derived'
abstract.cpp:(.text+0x29): undefined reference to `Derived::Run()'
/tmp/cckxMhvH.o: In function `Derived::~Derived()':
abstract.cpp:(.text._ZN7DerivedD2Ev[_ZN7DerivedD5Ev]+0xd): undefined reference to `vtable for Derived'
collect2: error: ld returned 1 exit status
#ifndef IBASE_H
#define IBASE_H
class IBase{
public:
virtual ~IBase(){}
virtual void Run() = 0;
};
#endif
@davamix
Copy link
Author

davamix commented Jan 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment