473,785 Members | 3,417 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

illegal call of non-static member function [why???]

I'm getting the following compile-time error:

error C2352: 'Person::getCou nt' : illegal call of non-static member
function

Here is my getCount function declaration:
-----------------------------------------------------------------------------------
//person.h
class Person
{
....
public:
...
int getCount();
}
----------------------------------------------------------------------------------
//person.cpp
int Person::getCoun t()
{
return count;
}
----------------------------------------------------------------------------------
//test.cpp
int main()
{
....
for (int i = 0; i < Person::getCoun t(); i++)
persPtr[i]->print();
int total = Person::getCoun t();
....
}
-----------------------------------------------------------------------------------

Do you see something that I don't? Mind I'm a bit of a beginner with C+
+. I've spent far too long trying to figure this one out.

Thanks in advance for any help.

Apr 17 '07
10 32211
anon wrote:
shanknbake wrote:
>I tried using 'static int getCount()' so that Public::getCoun t() would
work, but it give me problems with not being able to use the member
variable 'int count'. Take a look (I'll give my entire program here)
---------------------------------------------------------------------------------------------------------------------------------------------------------

http://rafb.net/p/Cwqix279.html

The error I got is listed at the top.

I'm still very VERY foggy on this whole "static member variable /
static function...etc. .." stuff. I've never learned it before and so I

**after reading your code**
count needs to be static as well, and you need to lower it in the
Person's destructor
Just a small add: using static data like that, you are risking a
possible Static Order Fiasco. Better take a look in the FAQ about static
members
Apr 18 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
2955
by: dingbat | last post by:
I'm writing a "tabbed folder" nav bar. Site standards are graphical prettiness, CSS throughout, valid code, but accesibility is ignored where it conflicts with prettiness. The particular issue here is that the graphic designer wants a pretty (non-webbable) font on the shaded nav tabs, so I'm reduced to using bitmaps. To make the 4-way rollovers ("current" and "hover" states) work I'm using the standard "rollerblind" technique with a...
14
42429
by: deko | last post by:
Is there a way to check user input for illegal characters? For example, a user enters something into a text box and clicks OK. At that point I'd like to run code such as this: illegal = Array(\, /, :, *, ?, ", <, >, |) If Me.TextBox Contains illegal Then MsgBox "You entered illegal characters. Please try again." Me.TextBox = Null
4
2814
by: Logu | last post by:
I have an interesting issue. rather I should call this as confusing issue. :-) I have a small proto in my project, which should act as a server, which essentially requests info and passes the info to another hardware interface. Since this is a non-critical piece, I simply had UNC Path to transfer the info as XML. But even at my initial testing of the application, I had bloopers
12
2378
by: [Yosi] | last post by:
What I should do to return back the permissin I had in VS2003 , that allowd me to access public methode of one Class from other Thread. I have Class A(FORM) which create new thread (new class B), the new class thread get as parameter reference to his father( CLASS who mad it (classA)), The new thread need to call methodes from his father like myfathe.methode(), This worked in VS 2003 but now in VS 2005 Beta throw an exception : An...
12
7198
by: Wilfried Mestdagh | last post by:
Hi, Using P/Invoke I use PostMessage to send a message from one thread to another. I'm pretty sure this has already worked in dotnet. but I've upgraded version 2 few day ago. Now I have an illegal cross thread operation if posting a message. Is this a bug introduced in latest version of dotnet ? It is very legal to use postmessage because the message will execute in context of the thread the one was posted to. Same with...
0
1076
by: Expert Humor | last post by:
The way our politicians rushed to talk about illegal immigration this week, maybe they thought it came with a free lunch. They won't do anything about it, but it will get them some money. The Expert provides the details at: http://www.ExpertHumor.com/
5
8014
by: Roy Smith | last post by:
The following code appears to be illegal: while ((int c = getchar()) != EOF) { putchar (c); } I tried it on two different compilers (Sun workshop and gcc), and both give some variation on syntax error at "int c =". The very similar: for (int c = getchar(); c != EOF; c = getchar()) {
4
4022
by: Mathias Waack | last post by:
Hi, I've embedded python into a legacy application. It works - most of the time. In some special situations the app crashes executing the "import random". There are two different situations: 1. the sources compiled with gcc 4.1.2 crash with illegal instruction error: (running my application)
1
13054
by: Manish | last post by:
The code is as ... $folderlistfile = $path."xmlfile.xml"; /* <list> <details id="2"> <name>Books</name>
22
7273
by: smarty | last post by:
this code gives an "illegal seek error" on close() call what is this error and when does it come? main() { int fd,num; char buf; fd = open ("123.c",O_RDWR); if(fd!=-1) {
0
9643
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10085
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.