473,474 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with static variable

blackstormdragon
32 New Member
In my program I have a static variable that I declared, but when I debug my program is tells me that it hasn't been initialized.
Expand|Select|Wrap|Line Numbers
  1. class HotDogStand
  2. {
  3. public:
  4.     HotDogStand(int standID, int dogSold);
  5.     void JustSold();
  6.     int ReturnJustSold();
  7.     static int TotalDogSold(int total);
  8.  
  9. private:
  10.     int _standID, _dogSold;
  11.     static int _totalDogSold;
  12. };
  13.  
  14. int HotDogStand::_totalDogSold = 0;
  15.  
  16. void main()
I initialized the static variable outside of the class and it looks like the example in my book, so I don't understand whats wrong.
Thanks
Sep 14 '07 #1
3 1230
Ganon11
3,652 Recognized Expert Specialist
I don't have a textbook in front of me, but try adding the static keyword to your initialization? i.e.

Expand|Select|Wrap|Line Numbers
  1. static int HotDogStand::_totalDogSold = 0;
Sep 14 '07 #2
RRick
463 Recognized Expert Contributor
This compiled fine with Linux gnu g++, except for the main() at the end.

I assume this is a code snippet, because the body for main is not defined, and my compiler won't let me compile a void main(). It wants an int main()
Sep 14 '07 #3
blackstormdragon
32 New Member
Thanks for the help, it seems my problem was else where. When I went to post some more code here, I saw my problem clear as day. So thanks for the help, both of you.
Sep 14 '07 #4

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

Similar topics

2
by: Vinay Aggarwal | last post by:
I have been thinking about the lazy initialization and double checked locking problem. This problem is explain in detail here http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html...
5
by: chandra sekhar | last post by:
Hi All, I am trying to allocate memory for member variable in a static method belongs to same class.. the allocation is o.k and when try to access the member variable I find that it is a null...
4
by: Bangalore | last post by:
Hi all, I am finding quite difficulty in understanding the behaviour of the following program. Base class is singleton, so it should allow the creation of only one object. Eventhough it is...
28
by: Dennis | last post by:
I have a function which is called from a loop many times. In that function, I use three variables as counters and for other purposes. I can either use DIM for declaring the variables or Static. ...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
2
by: hemant.singh | last post by:
I am stuck with strange JS issue My product gives user to show some images(which track mouseover) on page by embedding script like <script src=http://domain.com/GetDynamicJS?domagic=1>...
78
by: Josiah Manson | last post by:
I found that I was repeating the same couple of lines over and over in a function and decided to split those lines into a nested function after copying one too many minor changes all over. The only...
6
by: toton | last post by:
Hi, If I have a singleton class based on dynamic initialization (with new ) , is it considered a memory leak? Anything in C++ standard says about it ? And little off - topic question , If the...
10
by: Pramod | last post by:
Hello to all of you, I want to know that what's the use to create static object. Thanks You Pramod Sahgal
2
by: Jeff | last post by:
Hey ..NET 2.0 I'm developing an application which will perform some webservice calls and I believe having those calls in a separate thread may help the app run smoother No user are waiting...
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...
1
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,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.