By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,264 Members | 1,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,264 IT Pros & Developers. It's quick & easy.

C++20: Technical Question on upcoming Modules

P: 1
Suppose a module M has an exported method foo whose implementation uses class myclass and/or method mymethod that originiate in an unrelated module or header and the module doesn't export them . Also implemetation of this method foo is exported in the module M.https://speedtest.vet/

Can one import the module and use the function foo from another library doesn't import of either myclass or mymethod? Technically, one can use implementation that supplied by the module so it can work.

Why the question? Suppose I have a simple function foo that can be inlined (fully or not fully as it might call some other heavy methods but it will at least save unnecessary function call). However, to compile and inline it one needs to import an additional header or module and I want to minimize header-level dependencies.

So the question is in short, is it possible to use exported method whose implementation is also exported - yet my current module is unable to compile it due to dependencies issue? Or the implementation must not be exported in this case?

Edit: from the replies it is understood the classification of "visible" and "reachable" methods/classes essentialy solve the issue. However, now I have another question: When ODR violation happens? When visible objects have identical names or even when reachable objects have the same name?

In similar note, consider diamond problem in modules. struct X is used by module A and module B yet none of them export it. Can module B use struct X generated by A? If yes, then suppose struct X is defined differently in A and B will it result in UB or a sensible compiler/linker error?
Apr 9 '20 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.