Hi @Osman Zakir ,
There are several mistakes in your code, after correcting the program will work.(Be sure to export the classes and methods to be used in modules using export
.)
- In Package.ixx you need to add
export
. export module truckload:package;
import :shared_box;
export class Package
{
public:
Package(SharedBox box) : m_box{ box }, m_next{ nullptr } {}
~Package() { delete m_next; }
SharedBox get_box() const { return m_box; }
Package* get_next() { return m_next; }
void set_next(Package* package) { m_next = package; }
SharedBox m_box;
Package* m_next;
}; - The function
addbox
and the variablebox_perline
are named incorrectly in Truckload.cpp module truckload;
import :package;
import <iostream>; void Truckload::list_boxes() const
{
const std::size_t boxes_perline{ 4 };
std::size_t count{};
for (Package* e{ m_head }; e; e = e->get_next())
{
std::cout << ' ';
e->get_box()->list_box();
if (!(++count % boxes_perline))
{
std::cout << std::endl;
}
}
if (count % boxes_perline)
{
std::cout << std::endl;
}
} SharedBox Truckload::get_first_box()
{
m_current = m_head;
return m_current ? m_current->get_box() : nullptr;
} SharedBox Truckload::get_next_box()
{
if (!m_current)
{
return get_first_box();
}
} Truckload::Truckload(const std::vector<SharedBox>& boxes)m_current = m_current->get_next(); return m_current ? m_current->get_box() : nullptr;
{
for (const auto& box : boxes)
{
add_box(box);
}
} Truckload::Truckload(const Truckload& src)
{
for (Package* e{ src.m_head }; e; e = e->get_next())
{
add_box(e->get_box());
}
} void Truckload::add_box(SharedBox box)
{
auto package{ new Package{box} };
if (m_tail)
{
m_tail->set_next(package);
}
else
{
m_head = package;
}
} bool Truckload::remove_box(SharedBox box_to_remove)m_tail = package;
{
Package* previous{ nullptr };
Package* current{ m_head };
while (current)
{
if (current->get_box() == box_to_remove)
{
if (previous)
{
previous->set_next(current->get_next());
}
}if (current == m_head) { m_head = current->get_next(); } if (current == m_tail) { m_tail = previous; } if (current == m_current) { m_current = m_current->get_next(); } current->set_next(nullptr); delete current; return true; } previous = current; current = current->get_next(); } return false;
Best regards,
Elya
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.