Friend of the class is inaccesible - c++

i am trying to write a very simple code as a practice. The problem is when i make friend a member function of one class to another, it says inaccesible but when i declare the whole class as friend of another class it works fine.
#include <iostream>
using namespace std;
class gpa2;
class gpa1 {
private:
int no1;
int no2;
public:
void setnum1(int n1, gpa2&xp) {
cout << " the friend member function is : " << xp.no4;
}
void setnum2(int n2) {
no2 = n2;
cout << "num2 is : " << no2 << endl;
};
};
class gpa2 {
private:
int no3;
int no4;
friend void gpa1::setnum1(int, gpa2&);
public:
void setnum3(int n3) {
no3 = n3;
cout << "num3 is : " << no3 << endl;
}
void getnum4(int n4) {
cout << "num4 is : " << n4 << endl;
}
};
int main() {
gpa1 g1;
gpa2 g2;
g1.setnum1(15, g2);
g1.setnum2(30);
g2.setnum3(45);
g2.getnum4(50);
return 0;
}

xp.no4 is not accessible, as setnum1 is a member function of gpa1, not gpa2
Implementing the function setnum1(int, gpa2&) is not necessary when defining it, and causing problems here: At the time of defining class gpa1 setnum1 can't be implemented, as class gpa2 is not yet defined. BUT implementing it after defining gpa2 is no problem at all.
Therefore, with some small changes: Godbolt example
#include <iostream>
using namespace std;
// forward declaration
class gpa2;
class gpa1 {
private:
int no1;
int no2;
public:
void setnum1(int n1, gpa2& xp);
void setnum2(int n2) {
no2 = n2;
cout << "num2 is : " << no2 << endl;
};
};
class gpa2 {
private:
int no3;
int no4;
friend void setnum1(int, gpa2&);
public:
void setnum3(int n3) {
no3 = n3;
cout << "num3 is : " << no3 << endl;
}
void getnum4(int n4) {
cout << "num4 is : " << n4 << endl;
}
int num4() { return no4; } // added accesibility to no4
};
// implementation of setnum1
void gpa1::setnum1(int n1, gpa2& xp) {
cout << " the friend member function is : " << xp.num4();
}
int main() {
gpa1 g1;
gpa2 g2;
g1.setnum1(15, g2);
g1.setnum2(30);
g2.setnum3(45);
g2.getnum4(50);
return 0;
}

Related

Accessing a class member of pointer type to a nested class [duplicate]

For some reason I cannot use functions attached to the object I want to use. I added a comment to the line that is not working. As an error I get "Error; pointer to incomplete class type is not allowed" Please help
This is code in dokter.ccp
int counter = 0;
for (list<Wielrenner*>::iterator it = wielrenners.begin(); it != wielrenners.end(); it++){
Wielrenner* wielrennerOB = *it;
cout << "\nID: " << counter;
cout << "List size: " << persons.size() << endl;
wielrennerOB->print(); // This is not working
counter++;
}
This is code in wielrenner.h
#ifndef WIELRENNER_H_
#define WIELRENNER_H_
//#include <fstream>
#include "persoon.h"
#include "Onderzoek.h"
class Wielrenner :
public Persoon
{
public:
Wielrenner(string, string, Adres, string, Datum, Datum, string, int, float, float, float,list<Onderzoek>* );
~Wielrenner(void);
int getLengte() const;
float getGewicht() const;
float getVo2max() const;
float getMaxVermogen() const;
list<Onderzoek> getOnderzoekenList();
void setLengte(int);
void setGewicht(float);
void setVo2max(float);
void setMaxVermogen(float);
void voegOnderzoekToeList(Onderzoek);
void showOnderzoeksList();
void setOnderzoeksLijst(list<Onderzoek>&);
void print();
void printFile(ofstream&);
private:
int lengte;
float gewicht;
float vo2max;
float maxVermogen;
list<Onderzoek> onderzoeken;
};
#endif /* WIELRENNER_H_ */
code in wielrenner.CCP
using namespace std;
#include <string>
#include "Wielrenner.h"
/*
#include "Onderzoek.h"
*/
Wielrenner::Wielrenner(string voornaam, string achternaam, Adres adres, string telefoon, Datum datumInDienst, Datum geboorteDatum,
string persoonType, int lengte, float gewicht, float vo2max, float maxVermogen,list<Onderzoek>* onderzoeken)
: lengte(lengte),
gewicht(gewicht),
vo2max(vo2max),
maxVermogen(maxVermogen),
Persoon(voornaam, achternaam, adres, telefoon, datumInDienst, geboorteDatum, persoonType)
{
}
Wielrenner::~Wielrenner(void)
{
}
//setten van gegevens
void Wielrenner::setLengte(int newLengte){
lengte = newLengte;
}
void Wielrenner::setGewicht(float newGewicht){
gewicht = newGewicht;
}
void Wielrenner::setVo2max(float newVo2max){
vo2max = newVo2max;
}
void Wielrenner::setMaxVermogen(float newMaxVermogen){
maxVermogen = newMaxVermogen;
}
void Wielrenner::voegOnderzoekToeList(Onderzoek newOnderzoek){
onderzoeken.push_back(newOnderzoek);
}
void Wielrenner::showOnderzoeksList(){
int teller=0;
for (list<Onderzoek>::iterator it = onderzoeken.begin(); it != onderzoeken.end(); it++){
Onderzoek onderzoekOB = *it;
cout << teller << " - ";
onderzoekOB.print();
teller++;
}
}
void Wielrenner::setOnderzoeksLijst(list<Onderzoek>& newOnderzoeksLijst){
onderzoeken = newOnderzoeksLijst;
}
void Wielrenner::print(){
cout << "(" << persoonID << ") Persoon: " << endl;
cout << persoonType << endl;
cout << voornaam << " " << achternaam << endl;
adres.print();
cout << telefoon << endl;
cout << "Datum in dienst: ";
datumInDienst.print();
cout << "Geboortedatum: ";
geboorteDatum.print();
cout << "> Extra wielrenner gegevens: " << endl;
cout << "Lengte: " << lengte << endl;
cout << "Gewicht: " << gewicht << endl;
cout << "vo2max: " << vo2max << endl;
cout << "maxVermogen: " << maxVermogen << endl;
}
void Wielrenner::printFile(ofstream &myfile){
myfile << persoonID << "\n";
myfile << persoonType << "\n";
myfile << voornaam << " " << achternaam << "\n";
adres.printFile(myfile);
myfile << telefoon << "\n";
datumInDienst.printFile(myfile);
geboorteDatum.printFile(myfile);
myfile << lengte << "\n";
myfile << gewicht << "\n";
myfile << vo2max << "\n";
myfile << maxVermogen << "\n";
}
// returnen van gegevens
int Wielrenner::getLengte() const{
return lengte;
}
float Wielrenner::getGewicht() const{
return gewicht;
}
float Wielrenner::getVo2max() const{
return vo2max;
}
float Wielrenner::getMaxVermogen() const{
return maxVermogen;
}
list<Onderzoek> Wielrenner::getOnderzoekenList(){
return onderzoeken;
}
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
One thing to check for...
If your class is defined as a typedef:
typedef struct myclass { };
Then you try to refer to it as struct myclass anywhere else, you'll get Incomplete Type errors left and right. It's sometimes a mistake to forget the class/struct was typedef'ed. If that's the case, remove "struct" from:
typedef struct mystruct {}...
struct mystruct *myvar = value;
Instead use...
mystruct *myvar = value;
Common mistake.
You get this error when declaring a forward reference inside the wrong namespace thus declaring a new type without defining it. For example:
namespace X
{
namespace Y
{
class A;
void func(A* a) { ... } // incomplete type here!
}
}
...but, in class A was defined like this:
namespace X
{
class A { ... };
}
Thus, A was defined as X::A, but I was using it as X::Y::A.
The fix obviously is to move the forward reference to its proper place like so:
namespace X
{
class A;
namespace Y
{
void func(X::A* a) { ... } // Now accurately referencing the class`enter code here`
}
}
The problem also occurs when header files are not included explicitly where they are needed, but implicitly through other heading files.
I came accross the same problem and solved it by checking my #includes.
If you use QKeyEvent you have to make sure that you also include it.
I had a class like this and my error appeared when working with "event"in the .cpp file.
myfile.h
#include <QKeyEvent> // adding this import solved the problem.
class MyClass : public QWidget
{
Q_OBJECT
public:
MyClass(QWidget* parent = 0);
virtual ~QmitkHelpOverlay();
protected:
virtual void keyPressEvent(QKeyEvent* event);
};
Check out if you are missing some import.

To convert multi level to hierarchy inheritance in c++

When I tried to convert it the class result can't get the data from class marks even if I made the data variables of marks public I don't know why. I also declared a object of class marks in result and then tried to access it but failed again I am new to coding so don't know all the syntax correctly your help will be of great use
#include <string.h>
#include <iostream>
using namespace std;
class student {
private:
int rl;
char nm[20];
public:
void read();
void display();
};
class marks : public student {
protected:
int s1;
int s2;
int s3;
public:
void getmarks();
void putmarks();
};
class result : public marks {
private:
int t;
float p;
char div[10];
public:
void process();
void printresult();
};
void student::read() {
cout << "enter Roll no and Name " << endl;
cin >> rl >> nm;
}
void student::display() {
cout << "Roll NO:" << rl << endl;
cout << "name : " << nm << endl;
}
void marks ::getmarks() {
cout << "enter three subject marks " << endl;
cin >> s1 >> s2 >> s3;
}
void marks ::putmarks() {
cout << "subject 1:" << s1 << endl;
cout << "subject 2 :" << s2 << endl;
cout << "subject 3:" << s3 << endl;
}
void result::process() {
t = s1 + s2 + s3;
p = t / 3.0;
p >= 60 ? strcpy(div, "first")
: p >= 50 ? strcpy(div, "second")
: strcpy(div, "third");
}
void result::printresult() {
cout << "total = " << t << endl;
cout << "per = " << p << "%" << endl;
cout << "div = " << div << endl;
}
int main(){
result x;
x.read();
x.getmarks();
x.process();
x.display();
x.putmarks();
x.printresult();
}
#include<iostream>
#include<string.h>
using namespace std;
class marks // parent class
{
protected:
int s1;
int s2;
int s3;
public:
void getmarks();
void putmarks();
};
class student : public marks // child class
{
private:
int rl;
char nm[20];
public:
void read();
void display();
};
class result : public marks// child class
{
private:
int t;
float p;
char div[10];
public:
void process();
void printresult();
};
void student::read()
{
cout<<"enter Roll no and Name "<<endl;
cin>>rl>>nm;
}
void student:: display()
{
cout <<"Roll NO:"<<rl<<endl;
cout<<"name : "<<nm<<endl;
}
void marks ::getmarks()
{
cout<<"enter three subject marks "<<endl;
cin>>s1>>s2>>s3;
}
void marks ::putmarks()
{
cout <<"subject 1:"<<s1<<endl;
cout<<"subject 2 :"<<s2<<endl;
cout <<"subject 3:"<<s3<<endl;
}
void result::process()
{
t= s1+s2+s3;
p = t/3.0;
p>=60?strcpy(div,"first"):p>=50?strcpy(div, "second"): strcpy(div,"third");
}
void result::printresult()
{
cout<<"total = "<<t<<endl;
cout<<"per = "<<p<<"%"<<endl;
cout<<"div = "<<div<<endl;
}
int main()
{
result x;
student y;
y.read();
x.getmarks();
x.process();
y.display();
x.putmarks();
x.printresult();
}

How to change variable stored in parent class from an inherited class in C++

So as the title suggests I am attempting to change the number variable, originally stored as 1000. Change this variable in another class function, and then replace the original value (1000) with the newly updated number. I haven't been able to find anything online to help me with this.
I have tried using pointers to no avail.
#include <iostream>
using namespace std;
class data {
protected:
int number = 1000;
};
class fetchData : public data {
public:
int getNumber() {
return number;
}
int updateNumber(int newNumber) {
number = newNumber;
return number;
}
};
class function : public fetchData {
public:
void minusNumber(int numberTakeAway) {
int newNumber = number - numberTakeAway;
updateNumber(newNumber);
cout << "Taken away: " << numberTakeAway << endl;
cout << "\nShould be new number: " << number << endl; // Not updating parent class variable
}
};
void printData() {
fetchData r;
cout << "number: " << r.getNumber() << endl;
}
void minusNumber() {
function r;
r.minusNumber(200);
}
int main(void) {
fetchData q;
cout << "\nOriginal ";
printData();
cout << "\n";
minusNumber();
cout << "\nActual ";
printData();
cout << "\n";
return 0;
}
You seem to be confusing between static - class members, and non static - instance members.
number is an instance member which means every instance will have its own number with its own value.
Each of your functions main, printData, and minusNumber creates its own instance of function or fetchData class, and there is no connection between them.
Try this code, where there is only one instance:
int main(void) {
function q;
cout << "\nOriginal ";
q.printData();
cout << "\n";
q.minusNumber(200);
cout << "\nActual ";
q.printData();
cout << "\n";
return 0;
}
What you have done in the free functions is to create a new instance of your class. If you want to do something with q that you instantiated in main, you have to pass it. Or use the member function in your class. So below, I've changed printData to take a reference to q. And instead of calling the free function minusNumber, I've called the member function of your class. I deleted the free function as it is not used.
#include <iostream>
class data {
protected:
int number = 1000;
};
class fetchData : public data {
public:
int getNumber() const {
return number;
}
int updateNumber(int newNumber) {
number = newNumber;
return number;
}
};
class function : public fetchData {
public:
void minusNumber(int numberTakeAway) {
int newNumber = number - numberTakeAway;
updateNumber(newNumber);
std::cout << "Taken away: " << numberTakeAway << std::endl;
std::cout << "\nShould be new number: " << number << std::endl; // Not updating parent class variable
}
};
void printData(const function& r) {
std::cout << "number: " << r.getNumber() << std::endl;
}
int main(void) {
function q;
std::cout << "\nOriginal ";
printData(q);
std::cout << "\n";
q.minusNumber(200);
std::cout << "\nActual ";
printData(q);
std::cout << "\n";
return 0;
}

Resolve ambiguity resulting from multiple inheritance of classes which share a common template class

I am trying to create a base class which is a template class and accepts, as a templace, some class. This base class in the parent class of two other classes which are themselves the parents of the final class. Thus, I have the traditional diamond problem in c++ with the addition that the root base class is a template class. Using virtual inheritance here does not quite do the trick.
Edit: Included some code (and corrected typos)
#include<iostream>
#include<string>
using namespace std;
template<class TemplateT>
class MainMaster {
protected:
std::string name;
int number;
TemplateT variableProp;
public:
explicit MainMaster(std::string, int);
void setName(std::string);
std::string getName();
void printName();
void setNumber(int);
int getNumber();
void printNumber();
void printMasterProperties(std::string);
void setVarProp(TemplateT);
TemplateT getVarProp();
};
template<class TemplateT>
MainMaster<TemplateT>::MainMaster(std::string nameIn, int numIn){
setName(nameIn);
setNumber(numIn);
}
template<class TemplateT>
void MainMaster<TemplateT>::setName(std::string nameIn){ name = nameIn; }
template<class TemplateT>
std::string MainMaster<TemplateT>::getName(){ return name; }
template<class TemplateT>
void MainMaster<TemplateT>::printName(){ cout << "Master's name is " << name << endl; }
template<class TemplateT>
void MainMaster<TemplateT>::setNumber(int numIn){ number = numIn; }
template<class TemplateT>
int MainMaster<TemplateT>::getNumber(){ return number; }
template<class TemplateT>
void MainMaster<TemplateT>::printNumber(){ cout << name << "'s number is " << number << endl; }
template<class TemplateT>
void MainMaster<TemplateT>::printMasterProperties(std::string pre = ""){
cout << pre << "Master Properties" << endl
<< pre << "-Number: " << number << endl;
}
class ChildOne: public virtual MainMaster<std::string>{
protected:
std::string propOne;
public:
// using MainMaster::MainMaster;
ChildOne(std::string nameIn, int numIn, std::string p1);
void printName();
void setPropOne(std::string);
std::string getPropOne();
void printOnesProps(std::string);
};
ChildOne::ChildOne(std::string nameIn, int numIn, std::string p1): MainMaster<std::string>(nameIn,numIn){
setPropOne(p1);
}
void ChildOne::printName(){ cout << "ChildOne's name is " << name << endl; }
void ChildOne::setPropOne(std::string propIn){ propOne = propIn; }
std::string ChildOne::getPropOne(){ return propOne; }
void ChildOne::printOnesProps(std::string pre = ""){
printMasterProperties("-");
cout << pre << "One Properties" << endl
<< pre << "-PropOne: " << propOne << endl;
}
class ChildTwo: public virtual MainMaster<int>{
protected:
std::string propTwo;
public:
ChildTwo(std::string nameIn, int numIn, std::string p2);
void printName();
void setPropTwo(std::string);
std::string getPropTwo();
void printTwosProps(std::string);
};
ChildTwo::ChildTwo(std::string nameIn, int numIn, std::string p2): MainMaster<int>(nameIn,numIn){
setPropTwo(p2);
}
void ChildTwo::printName(){
cout << "ChidTwo's name is " << name << endl;
}
void ChildTwo::setPropTwo(std::string propIn){ propTwo = propIn; }
std::string ChildTwo::getPropTwo(){ return propTwo; }
void ChildTwo::printTwosProps(std::string pre = ""){
printMasterProperties("-");
cout << pre << "Two Properties" << endl
<< pre << "-PropTwo: " << propTwo << endl;
}
class FinalChild: public ChildOne, public ChildTwo{
protected:
double finalProp;
public:
FinalChild(std::string nameIn, int num, std::string prop1 ,std::string prop2, double pFinal);
void printFinalProps(std::string);
};
FinalChild::FinalChild(std::string nameIn, int num, std::string prop1 ,std::string prop2, double pFinal):
ChildOne(nameIn, num, prop1),
ChildTwo(nameIn, num, prop2),
MainMaster(nameIn, num){
finalProp = pFinal;
}
void FinalChild::printFinalProps(std::string pre = ""){
printMasterProperties("-");
cout << pre << name << "'s Final Properties" << endl;
cout << pre << "-Number: " << number << endl;
cout << pre << "-PropOne: " << propOne << endl;
cout << pre << "-PropTwo: " << propTwo << endl;
cout << pre << "-finalProp " << finalProp << endl;
}
int main () {
MainMaster<char> master("Master", 0);
ChildOne child1("Child1",1,"P1One");
ChildTwo child2("Child2",2,"P2Two");
FinalChild finalC("FinalChild", 3, "P1Final", "P2Final", 3.0);
master.printMasterProperties();
child1.printOnesProps();
child2.printTwosProps();
finalC.printFinalProps();
}

Pointer to incomplete class type is not allowed

For some reason I cannot use functions attached to the object I want to use. I added a comment to the line that is not working. As an error I get "Error; pointer to incomplete class type is not allowed" Please help
This is code in dokter.ccp
int counter = 0;
for (list<Wielrenner*>::iterator it = wielrenners.begin(); it != wielrenners.end(); it++){
Wielrenner* wielrennerOB = *it;
cout << "\nID: " << counter;
cout << "List size: " << persons.size() << endl;
wielrennerOB->print(); // This is not working
counter++;
}
This is code in wielrenner.h
#ifndef WIELRENNER_H_
#define WIELRENNER_H_
//#include <fstream>
#include "persoon.h"
#include "Onderzoek.h"
class Wielrenner :
public Persoon
{
public:
Wielrenner(string, string, Adres, string, Datum, Datum, string, int, float, float, float,list<Onderzoek>* );
~Wielrenner(void);
int getLengte() const;
float getGewicht() const;
float getVo2max() const;
float getMaxVermogen() const;
list<Onderzoek> getOnderzoekenList();
void setLengte(int);
void setGewicht(float);
void setVo2max(float);
void setMaxVermogen(float);
void voegOnderzoekToeList(Onderzoek);
void showOnderzoeksList();
void setOnderzoeksLijst(list<Onderzoek>&);
void print();
void printFile(ofstream&);
private:
int lengte;
float gewicht;
float vo2max;
float maxVermogen;
list<Onderzoek> onderzoeken;
};
#endif /* WIELRENNER_H_ */
code in wielrenner.CCP
using namespace std;
#include <string>
#include "Wielrenner.h"
/*
#include "Onderzoek.h"
*/
Wielrenner::Wielrenner(string voornaam, string achternaam, Adres adres, string telefoon, Datum datumInDienst, Datum geboorteDatum,
string persoonType, int lengte, float gewicht, float vo2max, float maxVermogen,list<Onderzoek>* onderzoeken)
: lengte(lengte),
gewicht(gewicht),
vo2max(vo2max),
maxVermogen(maxVermogen),
Persoon(voornaam, achternaam, adres, telefoon, datumInDienst, geboorteDatum, persoonType)
{
}
Wielrenner::~Wielrenner(void)
{
}
//setten van gegevens
void Wielrenner::setLengte(int newLengte){
lengte = newLengte;
}
void Wielrenner::setGewicht(float newGewicht){
gewicht = newGewicht;
}
void Wielrenner::setVo2max(float newVo2max){
vo2max = newVo2max;
}
void Wielrenner::setMaxVermogen(float newMaxVermogen){
maxVermogen = newMaxVermogen;
}
void Wielrenner::voegOnderzoekToeList(Onderzoek newOnderzoek){
onderzoeken.push_back(newOnderzoek);
}
void Wielrenner::showOnderzoeksList(){
int teller=0;
for (list<Onderzoek>::iterator it = onderzoeken.begin(); it != onderzoeken.end(); it++){
Onderzoek onderzoekOB = *it;
cout << teller << " - ";
onderzoekOB.print();
teller++;
}
}
void Wielrenner::setOnderzoeksLijst(list<Onderzoek>& newOnderzoeksLijst){
onderzoeken = newOnderzoeksLijst;
}
void Wielrenner::print(){
cout << "(" << persoonID << ") Persoon: " << endl;
cout << persoonType << endl;
cout << voornaam << " " << achternaam << endl;
adres.print();
cout << telefoon << endl;
cout << "Datum in dienst: ";
datumInDienst.print();
cout << "Geboortedatum: ";
geboorteDatum.print();
cout << "> Extra wielrenner gegevens: " << endl;
cout << "Lengte: " << lengte << endl;
cout << "Gewicht: " << gewicht << endl;
cout << "vo2max: " << vo2max << endl;
cout << "maxVermogen: " << maxVermogen << endl;
}
void Wielrenner::printFile(ofstream &myfile){
myfile << persoonID << "\n";
myfile << persoonType << "\n";
myfile << voornaam << " " << achternaam << "\n";
adres.printFile(myfile);
myfile << telefoon << "\n";
datumInDienst.printFile(myfile);
geboorteDatum.printFile(myfile);
myfile << lengte << "\n";
myfile << gewicht << "\n";
myfile << vo2max << "\n";
myfile << maxVermogen << "\n";
}
// returnen van gegevens
int Wielrenner::getLengte() const{
return lengte;
}
float Wielrenner::getGewicht() const{
return gewicht;
}
float Wielrenner::getVo2max() const{
return vo2max;
}
float Wielrenner::getMaxVermogen() const{
return maxVermogen;
}
list<Onderzoek> Wielrenner::getOnderzoekenList(){
return onderzoeken;
}
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
One thing to check for...
If your class is defined as a typedef:
typedef struct myclass { };
Then you try to refer to it as struct myclass anywhere else, you'll get Incomplete Type errors left and right. It's sometimes a mistake to forget the class/struct was typedef'ed. If that's the case, remove "struct" from:
typedef struct mystruct {}...
struct mystruct *myvar = value;
Instead use...
mystruct *myvar = value;
Common mistake.
You get this error when declaring a forward reference inside the wrong namespace thus declaring a new type without defining it. For example:
namespace X
{
namespace Y
{
class A;
void func(A* a) { ... } // incomplete type here!
}
}
...but, in class A was defined like this:
namespace X
{
class A { ... };
}
Thus, A was defined as X::A, but I was using it as X::Y::A.
The fix obviously is to move the forward reference to its proper place like so:
namespace X
{
class A;
namespace Y
{
void func(X::A* a) { ... } // Now accurately referencing the class`enter code here`
}
}
The problem also occurs when header files are not included explicitly where they are needed, but implicitly through other heading files.
I came accross the same problem and solved it by checking my #includes.
If you use QKeyEvent you have to make sure that you also include it.
I had a class like this and my error appeared when working with "event"in the .cpp file.
myfile.h
#include <QKeyEvent> // adding this import solved the problem.
class MyClass : public QWidget
{
Q_OBJECT
public:
MyClass(QWidget* parent = 0);
virtual ~QmitkHelpOverlay();
protected:
virtual void keyPressEvent(QKeyEvent* event);
};
Check out if you are missing some import.