473,320 Members | 1,940 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,320 software developers and data experts.

Help with Static Variables in a Class

2
I have the follwoing in a header file

class App
{

App();
~App();
static int batch_size;

}

int App::batch_size;


When I compile this code, I get an Error of Multiple definition of App::batch_size.


I am taking over a code which was written by someone else and am trying to compile it on a Linux machine. This code was originally written for a Sun Solaris UNIX box.

Please help !!!!
Aug 3 '07 #1
3 1178
r035198x
13,262 8TB
I have the follwoing in a header file

class App
{

App();
~App();
static int batch_size;

}

int App::batch_size;


When I compile this code, I get an Error of Multiple definition of App::batch_size.


I am taking over a code which was written by someone else and am trying to compile it on a Linux machine. This code was originally written for a Sun Solaris UNIX box.

Please help !!!!
The modifier static has several meanings in C++ depending on the context. Look it up and you should be able to understand why you got the error.
Aug 3 '07 #2
JosAH
11,448 Expert 8TB
I have the follwoing in a header file

class App
{

App();
~App();
static int batch_size;

}

int App::batch_size;


When I compile this code, I get an Error of Multiple definition of App::batch_size.


I am taking over a code which was written by someone else and am trying to compile it on a Linux machine. This code was originally written for a Sun Solaris UNIX box.

Please help !!!!
What happens if you initialize that thing, as in:

Expand|Select|Wrap|Line Numbers
  1. int App::batch_size= 0;
  2.  
... but don't do that in your header file. Do it in a dedicated .cpp file so you end
up with one single definition and initialization.

kind regards,

Jos
Aug 3 '07 #3
mghari
2
Thank you very much Jos, it fixed the issue. lemme know where I can send the million dollars. :)
Aug 3 '07 #4

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

Similar topics

9
by: Neil Kiser | last post by:
I'm trying to understand what defining a class as 'static' does for me. Here's an example, because maybe I am thinking about this all wrong: My app will allows the user to control the fonts...
4
by: Dave | last post by:
I used the following class and .aspx code below to understand how static works on variables and methods taken from...
11
by: dhnriverside | last post by:
Hi peeps Ok, so I thought I'd have a go at making a console app in VS2k5... I haven't written any windows apps for years, let alone dos apps (been web programming) and I've hit a dumb error... ...
4
by: Bryan Green | last post by:
So I'm working on a project for a C# class I'm taking, where I need to keep some running totals via static variables. I need three classes for three different types of objects. The base class and...
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. ...
5
by: Jesper Schmidt | last post by:
When does CLR performs initialization of static variables in a class library? (1) when the class library is loaded (2) when a static variable is first referenced (3) when... It seems that...
5
by: mast2as | last post by:
Hi guys Here's the class I try to compile (see below). By itself when I have a test.cc file for example that creates an object which is an instance of the class SpectralProfile, it compiles...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
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
16
by: RB | last post by:
Hi clever people :-) I've noticed a lot of people stating not to use static variables with ASP.NET, and, as I understand it, the reason is because the variable is shared across user sessions -...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.