472,780 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 software developers and data experts.

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
2 37147
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Jinesh | last post by:
I illustrate the compiler error I get using the following example. --------------------------------------------------------------- Class ClassName { private: static const int constVarName = 100;...
7
by: Ook | last post by:
What am I doing wrong? This code gives a compile error: 'SortedList<T>::insert' : illegal call of non-static member function. I've tried several variations of this, but keep getting the same error....
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
6
by: Bill Rubin | last post by:
The following code snippet shows that VC++ 7.1 correctly compiles a static member function invocation from an Unrelated class, since this static member function is public. I expected to compile the...
0
by: HKSHK | last post by:
This list compares the error codes used in VB.NET 2003 with those used in VB6. Error Codes: ============ 3: This Error number is obsolete and no longer used. (Formerly: Return without GoSub)...
2
by: mahesh | last post by:
Can anyone direct me to the place where i find the solution for the error message "cannot call member function 'X' without object"??? thanks in advance
1
by: spamfree | last post by:
Hello, If anyone can give me some insight as to why this code fails to compile, I would be most appreciative. I have only been able to test it with gcc 3.4.4 and gcc 4.2.1, which both fail with...
1
by: BSand0764 | last post by:
I'm getting an error that I can't seem to resolve. When I compile the Functor related logic in a test program, the files compile and execute properly (see Listing #1). However, when I...
10
by: subramanian100in | last post by:
consider the following program: #include <iostream> using namespace std; class my_complex { public: friend ostream & operator<<(ostream &os, const my_complex &c);
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.