I have created a Node class and I am trying to add std::unique_ptr to a domain class with a std::vectorstd::unique_ptr<Node> (based on domain length and space subdivision). It seems that I have a linker error whenever I am trying to create the vector. I have made several tests but I am not seeing where this error is coming from. Would anyone have an idea?
Many thanks!
Domain.hpp
class Domain
{
public:
/*Domain(const double lowerBound, const double upperBound, const double dx)
{
createNodes(lowerBound, upperBound, dx);
//createFaces();
//createCells();
}*/
void addNode(const Node&& node);
void addCell(const Cell&& cell);
void addFace(const Face&& face);
void createNodes(const double lowerBound, const double upperBound, const double dx);
void createFaces();
void createCells();
private:
std::vector<std::unique_ptr<Node>> m_nodes;
std::vector<std::unique_ptr<Face>> m_faces;
std::vector<std::unique_ptr<Cell>> m_cells;
};
#endif // DOMAIN_h
Domain.cpp
#include <memory>
#include <vector>
#include <array>
#include <cassert>
#include <Cell.hpp>
#include <Domain.hpp>
#include <Face.hpp>
#include <Node.hpp>
void Domain::addNode(const Node&& node)
{
m_nodes.push_back(std::make_unique<Node>(node));
}
void Domain::addFace(const Face&& face)
{
assert(("Invalid node", !face.isValid()));
m_faces.push_back(std::make_unique<Face>(face));
}
void Domain::addCell(const Cell&& cell)
{
assert(("Invalid node", !cell.isValid()));
m_cells.push_back(std::make_unique<Cell>(cell));
}
void Domain::createNodes(const double lowerBound, const double upperBound, const double dx)
{
double x = lowerBound;
while(x <= upperBound){
addNode(Node(x));
x += dx;
}
if (x < upperBound + dx){
addNode(Node(upperBound));
}
}
void Domain::createFaces()
{
for(const auto& node : m_nodes){
addFace(Face(node.get(),node.get())); // for the moment, nodes are collapsed
}
}
void Domain::createCells()
{
for (size_t i = 0; i < m_faces.size() - 1; ++i) {
const auto& face1 = m_faces[i];
const auto& face2 = m_faces[i+1]; // Check if there is a next element
addCell(Cell(face1.get(),face2.get()));
}
}
main.cpp
#include <iostream>
#include <Domain.hpp>
#include <Mesh.hpp>
int main(){
double lowerBound = 0.0;
double upperBound = 10.0;
double dx = 1.0;
Domain domain;
domain.createNodes(lowerBound,upperBound,dx);
return 0;
}
I have tried only with the simplest structure which is the Node but unfortunately the error remains.
Initially, the createNodes(…) was in the Domain constructor, along with createFaces() and createCells() but I have removed it from there to have more control and put it directly within the main, but is did not work.