I'm new to C++ modules. I have a project MyProject which includes a module definition Model.ixx:
export module Model;
export import :Element;
And a partition in Element.ixx:
#include <string>
export module Model:Element;
export class Element {
private:
std::string m_name;
public:
Element(std::string name) {
m_name = name;
}
std::string getName() {
return m_name;
}
void setName(std::string name) {
m_name = name;
}
};
I've also got another project in the same solution, MyProjectTest, which has MyProject added as a reference and which has one file, MyProjectTest.cpp:
#include "pch.h"
#include "CppUnitTest.h"
import Model;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace GsnEdTest
{
TEST_CLASS(GsnEdTest)
{
public:
TEST_METHOD(TestAttributeInit)
{
std::string name = "Test";
Element e(name);
Assert::AreEqual(name, e.getName());
}
};
}
But compilation of that last file fails because it cannot find the module 'Model'. How do I make it visible?
You need to add C++ compiler addition options for Model.ixx and Element.ixx(Unit test Project's properties-> C++ -> Command Line: additional options):
Check the usage: /reference (Use named module IFC)