question

FakhriyorOtamirzaev-3986 avatar image
0 Votes"
FakhriyorOtamirzaev-3986 asked FakhriyorOtamirzaev-3986 commented

Implement module (.cppm) in separate file (MSVS2019 Community, c++20)

I've got compilation errors when I am trying to implement module in separate file. However compilation is successful when I implement module in .cppm file. What's wrong here? Is it due to experimental features or I should configure something in project's properties?

c++
· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@FakhriyorOtamirzaev-3986

According to the Doc:

You can create a module with a single interface file (.ixx) that exports names and includes implementations of all functions and types. You can also put the implementations in one or more separate implementation files, similar to how .h and .cpp files are used. The export keyword is used in the interface file only. An implementation file can import another module, but cannot export any names. Implementation files may be named with any extension. An interface file and the set of implementation files that back it are treated as a special kind of translation unit called a module unit. A name that is declared in any implementation file is automatically visible in all other files within the same module unit.

For larger modules, you can split the module into multiple module units called partitions. Each partition consists of an interface file backed by one or more implementation files. (As of Visual Studio 2019 version 16.2, partitions are not yet fully implemented.)

I suggest you could try to use vs2022 preview.

Could you please provide a sample to help us reproduce the issue?


1 Vote 1 ·

@JeanineZhang-MSFT
Thank you for quick reply!

There is some code in attachements to test it out (Gregoire M. - Professional C++ book). It's not production code for sure. I'm sorry about that. But it's quite enough to reproduce errors.

125869-airlineticket-cpp.txt125840-airlineticket-cppm.txt125926-airlinetickettest-cpp.txt


0 Votes 0 ·
JeanineZhang-MSFT avatar image JeanineZhang-MSFT FakhriyorOtamirzaev-3986 ·

@FakhriyorOtamirzaev-3986

I test the code you provided. I couldn't get any errors. (visual studio 2019 16.10.4)

126227-image.png

Could you please provide the error? Which version of VS are you using


1 Vote 1 ·
image.png (33.0 KiB)
Show more comments

0 Answers