Last active
January 2, 2018 02:08
-
-
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?
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 "IBase.h" | |
#include "Derived.h" | |
int main(){ | |
Derived d; | |
d.Run(); | |
} |
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 "IBase.h" | |
#include "Derived.h" | |
void Derived::IBase::Run(){ | |
std::cout << "Hello from derived" << std::endl; | |
} |
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
#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 |
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
/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 |
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
#ifndef IBASE_H | |
#define IBASE_H | |
class IBase{ | |
public: | |
virtual ~IBase(){} | |
virtual void Run() = 0; | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Possibly related: https://stackoverflow.com/questions/3749099/why-should-the-implementation-and-the-declaration-of-a-template-class-be-in-the