467,879 Members | 1,362 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,879 developers. It's quick & easy.

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?

Aug 1 '07 #1
  • viewed: 36342
Share:
2 Replies
Elliott <ew*****@gmail.comwrote:
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.
Aug 1 '07 #2
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

Aug 1 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Jinesh | last post: by
6 posts views Thread by Peter Frost | last post: by
1 post views Thread by spamfree | last post: by
1 post views Thread by BSand0764 | last post: by
10 posts views Thread by subramanian100in | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.