2

How do I import a module from another project within the same Visual Studio solution?


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?
This title and content for this question was made by "digitig" at this link: https://stackoverflow.com/questions/77385907/how-do-i-import-a-module-from-another-project-within-the-same-visual-studio-solu. Contributions on stackoverflow.com are made under this license.

C++ Windows

1 Answers

  • 0

    Clear browser history before redirecting to "category":

    this.location.replaceState('/'); // clears history
    this.router.navigate(['/category']);

    The content for this answer was made by "Set" at this link: https://stackoverflow.com/questions/42091951/canactive-url-added-to-history-even-when-returning-false/42092601#42092601. Contributions on stackoverflow.com are made under this license.

Give your answer

Be sure to answer with an explanation on why your solution works.

Don't see an answer for your question?
Ask here

Search tags used in this post