Error - Cannot call member function without object...



 DEVELOP > c-Plus-Plus > Error - Cannot call member function without object...

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
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
.



  Page 1 of 1

1

 


Related Articles
what does this error means "cannot call member function 'X' without object "
Help! SIGBUS (object specifc hardware error) when call function getline
how can i use array to be the object in class and call the member function?
how to call function for array of object
code portability and function call serialisation.
Converting VB6.0 external dll function call to Visual C++ .NET
call non-const function
Why call member function through this pointer?
can you return a void function call?
How to call a function with variable argument list...
Is it possible to call a function which name is given by a string?
How to Call Templatise function of class
parse error in gcc but success in vc.net, call a non_template class's template member function from a template class's member function!
"no matching function for call to"?
function call misinterpreted as a variable
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER