|
c++20 modules |
amstradcpc
Member #23,651
January 2023
|
I can't get the c++20 modules to work, I get this message -> [Note] C++20 'import' only available with '-fmodules-ts', which is not yet enabled with '-std=c ++20' I am using the devc++ ide of this page. And the w64devkit compiler from this page. |
Dizzy Egg
Member #10,824
March 2009
|
You probably will need to add -fmodules-ts to your compile options, but I do not know how to that with your IDE.
---------------------------------------------------- |
amstradcpc
Member #23,651
January 2023
|
.cpp import persona; #include <iostream> int main(){ Persona persona{ 21,80.20 }; std::cout<<"edad: "<<persona.get_edad()<<"\n"; std::cout<<"peso: "<<persona.get_peso()<<"\n"; std::cout<<"modulos"<<"\n"; return 0; } .cppm 1export module persona;
2
3export class Persona{
4private:
5 int m_edad{};
6 float m_peso{};
7public:
8 Persona(int edad,float peso):m_edad{edad},m_peso{peso}{
9 }
10
11 int get_edad(){
12 return m_edad;
13 }
14
15 float get_peso(){
16 return m_peso;
17 }
18};
This is the code that I am using for the test, I have used the -fmodules-ts command, in the tools options/compiler options but it still does not work |
Dizzy Egg
Member #10,824
March 2009
|
For it to work in Visual Studio I had to add module; at the top of the module file, like this: 1module; //add this line
2export module persona;
3
4export class Persona{
5private:
6 int m_edad{};
7 float m_peso{};
8public:
9 Persona(int edad,float peso):m_edad{edad},m_peso{peso}{
10 }
11
12 int get_edad(){
13 return m_edad;
14 }
15
16 float get_peso(){
17 return m_peso;
18 }
19};
---------------------------------------------------- |
amstradcpc
Member #23,651
January 2023
|
It doesn't work either, I get these messages: [Error] failed to read compiled module: No such file or directory |
Dizzy Egg
Member #10,824
March 2009
|
Edited: it must be that your IDE needs additional parameters to build the module before using it in main…
---------------------------------------------------- |
amstradcpc
Member #23,651
January 2023
|
It may be but without knowing how it cannot be used. |
Dizzy Egg
Member #10,824
March 2009
|
If you really want to use c++20 and modules, you may want to use a more complete IDE, like Visual Studio...
---------------------------------------------------- |
|