I'm hiding the implementation details of third party C++ graph library (LEMON graph library) from my project by doing the following :
API.h file
class Node;
using NodeId = unique_ptr<Node>;
class ProgramGraph {
private:
class ProgramGraphImpl;
ProgramGraphImpl* pimpl;
public:
ProgramGraph();
NodeId add_instr_node(int opcode, const string& desc, BlockId& parent);
...
};
API.cpp file
class Node {
public:
ListDigraph::Node node;
Node(ListDigraph::Node node) : node(node) {}
~Node() {}
};
class ProgramGraphImpl {
NodeId add_instr_node(int opcode, const string& desc, BlockId& parent) {
ListDigraph::Node n = pg.addNode(); // this is from the 3rd party library
unique_ptr<Node> uq = make_unique<Node>(Node(n));
node_map[n] = Instr(opcode, desc, parent); // Instr is another class defined in API.cpp
return uq;
}
...
};
NodeId ProgramGraph::add_instr_node(int opcode, const string& desc, BlockId& parent) {
return pimpl->add_instr_node(opcode, desc, parent);
}
I am using the API like this in some_other_file.cpp :
#include "API.h"
...
const NodeId& currMI = pg.add_instr_node(opcode, opcode_desc, block_id);
...
When I compile it, I get the error below (error: invalid application of 'sizeof' to an incomplete type program_graph::Node
) - any ideas ? Thank you.
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/c++/v1/__memory/unique_ptr.h:53:19: error: invalid application of 'sizeof' to an incomplete type 'program_graph::Node' static_assert(sizeof(_Tp) > 0, ^~~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/c++/v1/__memory/unique_ptr.h:318:7: note: in instantiation of member function 'std::default_delete<program_graph::Node>::operator()' requested here _ptr.second()(__tmp); ^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/c++/v1/__memory/unique_ptr.h:272:19: note: in instantiation of member function 'std::unique_ptr<program_graph::Node>::reset' requested here ~unique_ptr() { reset(); } ^ some_other_file.cpp:151:36: note: in instantiation of member function 'std::unique_ptr<program_graph::Node>::~unique_ptr' requested here const NodeId& currMI = pg.add_instr_node(opcode, opcode_desc, block_id);