Question
How to hide implementation details in C++ modules?
I am new to C++ modules. I am using Visual Studio 2022.
Let's say I am creating a DLL, and I don't want my users to see implementation details of my class. How can I achieve this in C++ modules? Mostly I am seeing examples over the Internet, implementing functions in the same file.
Can I safely say, module interfaces are similar to header files & module implementation is similar to cpp file?
Here is my example implementation, is this correct?
AnimalParent.ixx
export module Animal:Parent;
export class Animal
{
public:
virtual void say();
};
AnimalParent.cpp
module Animal:Parent;
#include <iostream>
void Animal::say()
{
std::cout << "I am Animal" << std::endl;
}
Animal.cat.ixx
export module Animal:Cat;
import :Parent;
export class Cat :public Animal
{
public:
void say() override;
};
AnimalCat.cpp
module Animal:Cat;
#include <iostream>
void Cat::say()
{
std::cout << "I am cat" << std::endl;
}
Animal.ixx
export module Animal;
export import :Parent;
export import :Cat;
Questions:
Is this implementation correct?
Can I safely assume that files contain
export module name(.ixx extension)
- similar to header files &module name
- similar to respective source file?If I shift this DLL to my customer, what all should I give? My DLL and the folder containing
.ixx
files?How will they integrate my DLL? In the current header files system, they will refer to the header files directory in
Additional include directories
, and link to the lib. Here, do they have to refer to the folder containing.ixx
files inAdditional include directories
& link the lib?