Error - Cannot call member function without object... - c++
This is a discussion on Error - Cannot call member function without object... - c++ ; 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 ...
-
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?
-
Re: Error - Cannot call member function without object...
Elliott <ewdicus> 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.
-
Re: Error - Cannot call member function without object...
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
Similar Threads
-
By Application Development in forum c++
Replies: 2
Last Post: 11-02-2007, 07:33 AM
-
By Application Development in forum c++
Replies: 7
Last Post: 09-17-2007, 02:11 PM
-
By Application Development in forum c++
Replies: 3
Last Post: 07-06-2007, 07:50 AM
-
By Application Development in forum c++
Replies: 14
Last Post: 06-16-2007, 08:56 AM
-
By Application Development in forum c++
Replies: 3
Last Post: 02-19-2007, 02:19 PM