473,396 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

"A non-static member reference must be made relative to a specific object"

Hey, I'm new to C++ so I've just been toying around with it, but every time I attempt to use a method inherited from the header file using the scope operator, I keep getting that message. Making it as straightforward as possible, this is the segment of code that brings up the error;


//---Data.h---
#include <iostream>
using namespace std;

class Data {
public :

int Fingers;
void WhichFinger(int I);
};



//---Data.cpp---
#include <iostream>
using namespace std;

#include "Data.h"

void const WhichFinger (int I){
if (I = 1){
std::cout << "Left Pinky Finger";
}

if (I = 2){
std::cout << "Left Ring Finger";
}

if (I = 3){
std::cout << "Left Middle Finger";
}

if (I = 4){
std::cout << "Left Index Finger";
}

if (I = 5){
std::cout << "Left Thumb";
}

if (I = 6){
std::cout << "Right Pinky Finger";
}

if (I = 7){
std::cout << "Right Ring Finger";
}

if (I = 8){
std::cout << "Right Middle Finger";
}

if (I = 9){
std::cout << "Right Index Finger";
}

if (I = 10){
std::cout << "Right Thumb";
}
};


//---Main.cpp---
#include <iostream>
using namespace std;

#include "Data.h"

int main (){
int number;
std::cin >> number;

(Error appears here) Data::WhichFinger(number);
}
Oct 22 '11 #1

✓ answered by weaknessforcats

I see the function WhichFinger but I do not see the function Data::Whichfinger.

Further, Data::WhichFinger is a member function so you will need a Data object in order to call it:

Data obj;
obj.WhichFinger(etc...) //calls Data::WhichFinger

2 11515
weaknessforcats
9,208 Expert Mod 8TB
I see the function WhichFinger but I do not see the function Data::Whichfinger.

Further, Data::WhichFinger is a member function so you will need a Data object in order to call it:

Data obj;
obj.WhichFinger(etc...) //calls Data::WhichFinger
Oct 22 '11 #2
Oh, alright, I see what the problem was. I was attempting to call the function outside of an object that had the function as a member. Thanks a lot for the answer
Oct 22 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Daniel Aarno | last post by:
Consider the following code: typedef int A; class B { public: B(A& var) : m_var(var) {} virtual ~B() {} protected:
3
by: Clay_Culver | last post by:
I have this code: typedef BraidedNode* (BraidedNode::*NodeGet)() const; NodeGet test() { return BraidedNode::getNextID; } This code compiles under MSVC 7.1, but g++ (GCC 3.4.4) will not...
5
by: Sharon | last post by:
Hi to all. How do i reference a class member dynamically? Somthing like: byte i = 35; Button currentButton = this; Thanks, Sharon.
1
by: Jeffrey Todd | last post by:
I need to process a specific Control in a Web Page's Controls collection. I do know the ID of the control. I simply need to pass a reference to it to another method. The following code works...
2
by: Alex Vinokur | last post by:
If a class contains a member that is a pointer, one should implement copy constructor. Should one implement copy constructor if a class contains a member that is a reference? -- Alex...
3
by: v4vijayakumar | last post by:
While we can do whatever we want to do with the member variables, with the member references, why member references are not common? Note: This is not homework question. :)
3
by: ww | last post by:
I read a couple of books that tells this, but seems not one can explain why is this thanks
6
by: fl | last post by:
Hi, There is a question about nonstatic member. C++ primer says: A nonstatic member is restricted to being declared as a pointer or reference to an object of its class. It only gives an example of...
4
by: nielsp | last post by:
Hi! Why does'nt the following work? #include <iostream> class X { public:
2
by: Noor Alsawadi | last post by:
Hi, i am a student, i have knowledge in java but im still a beginner in C++ . i am doing a simple inheritance program, where my base class has a header "clockType.h" and an implementation file "clock...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.