So I am having trouble with the following syntax in c++:
I am developing a c++ program on windows and using visual studio 2022. It is a simple console application using c++20.
I have the following class structure:
Class1 {
Class2 function();
}
Class2 {
Class1 function2();
}
Class1 Class2::function2() {
...
}
Class2 Class1::function1() {
...
}
This is only an example, and I know I can separate them into two files, I already tried it. I can not program these functions inline, because they are using the constructors of the other classes, so I can't just define them inside their own classes. I get a linker error.
Here is my exact problem:
class first_class {
public:
int some_other_func() {
return 0;
}
second_class upgrade();
};
class second_class {
public:
int some_func() {
return 0;
}
first_class downgrade() noexcept;
};
first_class second_class::downgrade() {
...
}
second_class first_class::upgrade() {
...
}
This all should be in one header file. But when I try to compile it, I get LNK2005
and LNK1169
.