Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ Build Error #202

Open
Gabriel-in-Toronto opened this issue Mar 15, 2022 · 5 comments
Open

C++ Build Error #202

Gabriel-in-Toronto opened this issue Mar 15, 2022 · 5 comments

Comments

@Gabriel-in-Toronto
Copy link

Gabriel-in-Toronto commented Mar 15, 2022

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).
@boothby
Copy link
Collaborator

boothby commented Mar 16, 2022

@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.

@Gabriel-in-Toronto
Copy link
Author

Gabriel-in-Toronto commented Mar 16, 2022

@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;

@boothby
Copy link
Collaborator

boothby commented Mar 16, 2022

Excellent, thanks!

Gabriel-in-Toronto added a commit to Gabriel-in-Toronto/minorminer that referenced this issue Mar 17, 2022
@Gabriel-in-Toronto
Copy link
Author

Gabriel-in-Toronto commented Mar 17, 2022

@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?

@boothby
Copy link
Collaborator

boothby commented Mar 17, 2022

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.

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

No branches or pull requests

2 participants