Can't compile my class. Getting error: error: field 'filename' has incomplete type
If I change QString filename
to QString *filename
, error goes off.. but I need to have QString filename
.
process.h:
#ifndef PROCESS_H
#define PROCESS_H
#include <QString>
class Process
{
public:
int pid;
QString filename;
Process(int pid, QString filename);
};
#endif // PROCESS_H
process.cpp:
#include "process.h"
Process::Process(int pid, QString filename)
{
this->pid = pid;
this->filename = filename;
}
What's wrong?
An incomplete type is a type that describes an identifier but lacks information needed to determine the size of the identifier. An incomplete type can be: A structure type whose members you have not yet specified. A union type whose members you have not yet specified.
An "incomplete class" is one declared but not defined. E.g. class Wielrenner; as opposed to class Wielrenner { /* class members */ }; You need to #include "wielrenner.h" in dokter.ccp.
You cannot declare any objects of the class type or refer to the members of a class until the declaration is complete. However, an incomplete declaration allows you to make specific references to a class prior to its definition as long as the size of the class is not required.
In my experience, when such weird errors like this appeared with no reason, most of the time it has been solved by changing some names, hence it was a name conflict. (but most of the time, I still didn't understand where was the conflict).
So I would desperately try to change the names of, in order:
PROCESS_H
Process
filename
process.h
and process.cpp
(if there are other folders with same file names, they will be compiled at the same place if you use qmake)pid
, because you are really desperate at this pointUse something you are really sure it can't be already used, like MySuperFancyProcess
;-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With