Unsolved Forward declaration of class QColor when pass by Value of Object of QColor
-
Hi All
I have file is -------- myModel.hclass QColor; --------------- forward declaration
class myModel : public QAbtrsatrcItemModel {
protected :
QColor getColor()
void setColor(QModelIndex& , QColor);
};file is myModel.cc
#include "myModel.h"
#include <QColor>QColor myModel:: getColor(QModelIndex& index) {
............
....
}
void myModel:setColor(QModelndex&,QColor) {
...
...
}As I understand the forward declaration of a class only works when we are using pointer to the class object but in this case we are using QColor as pass by value and return by Value , but my code is compliling and working .
Can someone explain me how ? -
@Qt-Enthusiast
because in your case it's enough for the compiler to know that the type exists. Since it's not accessing any members of it.
When you would move the implementation of the getter and setter to your header file the compiler would need to know more about the class and thus a simple forward declaration wouldn't be sufficient. -
So I conclude this code is fine . Please let me know your feedback
-
@Qt-Enthusiast said:
So I conclude this code is fine . Please let me know your feedback
sure. it compiles ;)