+ 2

Separate files for instance declarations?

I'm kind of new to c++, if I have a program with a lot of instances declared in the middle of the program and I want them to be in a separate file, like a header file, if I do that I only get a lot of errors, how can I fix this? Edit: I realized it doesn't give errors from declaring them, only when I use functions, is there any way to use functions in a header file? Like if I have a class called rectangle and I create a rectangle called 'r', then I have a function to change its color and I want to do that in the header file.

21st May 2019, 12:57 PM
Bara Like
Bara Like - avatar
2 Antworten
+ 5
This way you kill the linker man! Headers are public interface for your programs, they have their implementations in the source file. And instances should go to the main . There are exceptions like static linkage or extern but if you're new to the language avoid them . Stick to a normal structure Headers and sources define behaviour aaaa.h => aaaa.cpp bbb.h => bbb.cpp ... Main(){....// behaves
21st May 2019, 1:25 PM
AZTECCO
AZTECCO - avatar