Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Visual Studio 2022 – Modules (Intellisense errors)

I have 3 files, namely engineering.cpp, engineering.ixx and system.ixx. Contents briefly are:

system.ixx:

export module sys;
export import :engineering;

engineering.ixx

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

module;

#include <string>
#include <vector>

export module sys:engineering;

namespace sys::engineering
{

    export class Psychrometry
    {
       //more code here
    }
}

engineering.cpp

module;

#include <sstream>

module sys:engineering;

namespace sys::engineering
{
     //implementation of the class
}

In another cpp file I use it as:

import sys;
sys::engineering::Psychrometry psy;

The project compiles and works well but in engineering.cpp intellisense gives 99+ errors and code-completion and other basic facilities dont work.

However, if I make the following change to engineering.cpp:

//instead of module sys:engineering
module sys;

Now intellisense works well and the project still compiles and works. However, to my understanding the first approach (module sys:engineering) is correct rather than (module sys).

What am I missing? Thanks in advance.

(Visual Studio Community 2022 (64-bit) – Current Version 17.2.6)

>Solution :

Two module units cannot use the same module partition name. As such, sys:engineering cannot be used in two module units. No diagnostic is required, which is why you don’t get a compile error.

Also, if engineering.cpp is going to be a module implementation partition, then it must explicitly import the module if you want to use any of the declarations exported by the module interface. Non-partition implementation units automatically import the module interface.

The only reason to make a module implementation unit a partition is if you want to import that file elsewhere (perhaps to share declarations internal to the module). Otherwise, just make them non-partition implementation units.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading