minorminer
minorminer copied to clipboard
C++ Build Error
Description I am trying to follow the guides and build the example.cpp and I am getting a error that
object of abstract class type "MyCppInteractions" is not allowed:C/C++(322)
[example.cpp(32, 42): ]()pure virtual function "find_embedding::LocalInteraction::displayOutputImpl" has no overrider
[example.cpp(32, 42): ]()pure virtual function "find_embedding::LocalInteraction::displayErrorImpl" has no overrider
To Reproduce
Compile the example.cpp
g++ example.cpp -std=c++11 -o example -pthread
The output is
Starting build...
/usr/bin/g++ -fdiagnostics-color=always -g /home/minorminer/examples/example.cpp -o /home/minorminer/examples/example
/home/minorminer/examples/example.cpp: In function ‘int main()’:
/home/minorminer/examples/example.cpp:32:60: error: invalid new-expression of abstract class type ‘MyCppInteractions’
params.localInteractionPtr.reset(new MyCppInteractions());
^
/home/minorminer/examples/example.cpp:18:7: note: because the following virtual functions are pure within ‘MyCppInteractions’:
class MyCppInteractions : public find_embedding::LocalInteraction {
^~~~~~~~~~~~~~~~~
In file included from /home/minorminer/examples/../include/find_embedding/graph.hpp:21:0,
from /home/minorminer/examples/../include/find_embedding/find_embedding.hpp:23,
from /home/minorminer/examples/example.cpp:16:
/home/minorminer/examples/../include/find_embedding/util.hpp:111:18: note: virtual void find_embedding::LocalInteraction::displayOutputImpl(int, const string&) const
virtual void displayOutputImpl(int loglevel, const string&) const = 0;
^~~~~~~~~~~~~~~~~
/home/minorminer/examples/../include/find_embedding/util.hpp:114:18: note: virtual void find_embedding::LocalInteraction::displayErrorImpl(int, const string&) const
virtual void displayErrorImpl(int loglevel, const string&) const = 0;
^~~~~~~~~~~~~~~~
Build finished with error(s).
@Gabriel-in-Toronto can I ask why you closed this? I confirmed that it's an issue on my machine. If you've got a workaround, I'd encourage you to submit a PR. This is a low priority issue for me, but it is a bug.
@boothby Sorry for the confusion. Yes, it is a bug and I have found a way to solve it. I am not sure if I will submit the PR later but here are the changes I made for your reference.
--- a/examples/example.cpp
+++ b/examples/example.cpp
@@ -13,7 +13,7 @@
// limitations under the License.
class MyCppInteractions : public find_embedding::LocalInteraction {
public:
@@ -21,7 +21,8 @@ class MyCppInteractions : public find_embedding::LocalInteraction {
void cancel() { _canceled = true; }
private:
- virtual void displayOutputImpl(const std::string& mess) const { std::cout << mess << std::endl; }
+ void displayOutputImpl(const std::string& mess) const override { std::cout << mess << std::endl; }
+ void displayErrorImpl(const std::string& mess) const override { std::cout << mess << std::endl; }
virtual bool cancelledImpl() const { return _canceled; }
};
--- a/include/find_embedding/util.hpp
+++ b/include/find_embedding/util.hpp
@@ -94,10 +94,10 @@ class LocalInteraction {
public:
virtual ~LocalInteraction() {}
//! Print a message through the local output method
- void displayOutput(int loglevel, const string& msg) const { displayOutputImpl(loglevel, msg); }
+ void displayOutput(int loglevel, const string& msg) const { displayOutputImpl(msg); }
//! Print an error through the local output method
- void displayError(int loglevel, const string& msg) const { displayErrorImpl(loglevel, msg); }
+ void displayError(int loglevel, const string& msg) const { displayErrorImpl(msg); }
//! Check if someone is trying to cancel the embedding process
int cancelled(const clock::time_point stoptime) const {
@@ -108,10 +108,13 @@ class LocalInteraction {
private:
//! Print the string to a binding specified sink
- virtual void displayOutputImpl(int loglevel, const string&) const = 0;
+ virtual void displayOutputImpl(const string&) const = 0;
//! Print the error to a binding specified sink
- virtual void displayErrorImpl(int loglevel, const string&) const = 0;
+ virtual void displayErrorImpl(const string&) const = 0;
Excellent, thanks!
@boothby Hi, I try to submit a PR to close this issue, but it seems that it is failing on some test cases. Can you teach me how to run the test cases to help me further revise my code?
The easiest thing to do is to update the code in the PR (I've made some suggestions there) and push them to your repo. The tests will re-run.
The c++ tests are a little involved to run (sorry, I'm just running out the door), but the python integration testing is easily run through python -m pytest .
in the root directory of the repo.