When attempting to prototype a class, for example, with this code:
#include <iostream>
class Foobar;
int main(){
return 0;
}
class Foobar {
std::string Bar = "Bar";
public:
void Foo(){
std::cout << Bar;
}
};
The code compiles fine, no errors there. However, when trying to instance the class Foobar
,
/tmp/JZXb2XeBXl.cpp: In function 'int main()':
/tmp/JZXb2XeBXl.cpp:6:11: error: aggregate 'Foobar InstanceOfFoobar' has incomplete type and cannot be defined
6 | Foobar InstanceOfFoobar;
| ^~~~~~~~~~~~~~~~
Which is the same result as just removing the end definition of the class Foobar
. So clearly, the end definition of Foobar
is just being ignored, and the compiler is only doing anything with the declaration.
How could I prevent this, and instead make the definition of Foobar
not be ignored?