3
In my object orientation studies, I have seen many say that in creating classes it is necessary to create a header
, containing class, attributes and methods, and also another file cpp
to implement the methods. But I’m finding some classes on the internet where the methods are already defined in the class itself. For example:
class formaGeometrica{
private:
float area;
char nome[20];
int cor;
public:
formaGeometrica(void) {}
~formaGeometrica(void){}
void setNome(char *nome)
{
strcpy(nome, nome);
}
void setArea(float area)
{
this.area = area;
}
void setCor(int cor)
{
this.cor = cor;
}
}
In this case, the methods are being declared within the header
, right? Is that correct? Because so far, I always create a hpp
for the class and then implement it into a file cpp
. I have tried this case, implementing the direct methods in header
and the code worked perfectly, so it is not necessary to then implement in a cpp
?
I took this code in an object orientation tutorial. You would say half C on account of the
strcpy
?– Bruno Pinho
The use of array of
char
as a whole.– Maniero