Error - Cannot call member function without object...

E

Elliott

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?
 
D

Daniel T.

Elliott said:
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.
 
E

Elliott

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top