| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Elliott" |
| Date: |
01 Aug 2007 11:35:41 AM |
| Object: |
Error - Cannot call member function without object... |
Hello Everyone,
I have a function in a header (KeyDialog.h) as such:
void setKey(Key&);
The function implementation is as such (KeyDialog.cpp):
void KeyDialog::setKey(Key& k1)
{
Key::Key K1 = k1;
//unimportant
}
And I'm calling this function from another cpp file (mainwindow.cpp)
like so:
KeyDialog::setKey(enter);
When I compile I get the error: Cannot call member function 'void
KeyDialog::setKey(Key&)' without object...
This is probably stupidly simple, what am i missing?
.
|
|
| User: "Daniel T." |
|
| Title: Re: Error - Cannot call member function without object... |
01 Aug 2007 12:02:14 PM |
|
|
Elliott <ewdicus@gmail.com> wrote:
Hello Everyone,
I have a function in a header (KeyDialog.h) as such:
void setKey(Key&);
The function implementation is as such (KeyDialog.cpp):
void KeyDialog::setKey(Key& k1)
{
Key::Key K1 = k1;
//unimportant
}
And I'm calling this function from another cpp file (mainwindow.cpp)
like so:
KeyDialog::setKey(enter);
When I compile I get the error: Cannot call member function 'void
KeyDialog::setKey(Key&)' without object...
This is probably stupidly simple, what am i missing?
You are missing an object. Try one of these in the other cpp file:
KeyDialog kd;
kd.setKey( enter );
There is probably some other fundamental error in your code though. It
may be that your "setKey" function doesn't need an object and therefore
should not be in the KeyDialog class.
.
|
|
|
| User: "Elliott" |
|
| Title: Re: Error - Cannot call member function without object... |
01 Aug 2007 01:49:51 PM |
|
|
Wow, I feel a bit stupid...a bit of a duh moment...
I had:
KeyDialog dialog(this);
KeyDialog::setKey(enter);
dialog.exec();
When of course i needed to have:
KeyDialog dialog(this);
dialog.setKey(enter);
dialog.exec();
Thank you very much, your small bit of code helped tremendously
.
|
|
|
|
|

|
Related Articles |
|
|