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

Calling a variable ?

How does one call a variable defined in a class defined in file1.cpp
from another file file2.cpp. Or can one call a class from a different
file ?

(Besides the standard way to define the variable in a header file and
include this header file where required)
Jul 22 '05 #1
2 1448
Ian
mark wrote:
How does one call a variable defined in a class defined in file1.cpp
from another file file2.cpp. Or can one call a class from a different
file ?
Call a variable?
(Besides the standard way to define the variable in a header file and
include this header file where required)


Why would you want to do it another way?

You can provide a prototype in the compilation unit you want to make the
call from but this is tedious and a maintenance headache.

Ian
Jul 22 '05 #2
"mark" <ma*********@yahoo.com> wrote in message
How does one call a variable defined in a class defined in file1.cpp
from another file file2.cpp. Or can one call a class from a different
file ?
In file1.h declare the variable as extern. In file2.cpp include file1.h.

// file1.h
#if !defined(include_file1)
#define include_file1
extern int variable;
#endif

// file1.cpp
#include "file1.h"
int variable = 0;

// file2.cpp
#include "file2.h"
#include "file1.h" // variable
void f() {
++variable;
}

(Besides the standard way to define the variable in a header file and
include this header file where required)


Is what I describe the standard? Why do you not want to do this?
Jul 22 '05 #3

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

Similar topics

1
by: Andrew Wilkinson | last post by:
Hi, First off I know that in almost all cases this would be a terrible thing to do, but this is an unusual case where this makes sense. Basically I have a procedure where you pass a string...
8
by: Muthu | last post by:
I've read calling conventions to be the order(reverse or forward) in which the parameters are being read & understood by compilers. For ex. the following function. int Add(int p1, int p2, int...
30
by: Tim Marshall | last post by:
Here's the scenario, A2003, Jet back end, illustrated with some cut down code at the end of the post: A proc dims a snapshot recordset (dim rst as Dao.recordset) and opens it. There are several...
17
by: Bill Grigg | last post by:
I have been successfully calling DLL's using VC++ 6.0 and also using VC++7.1 (.NET). I only mention this because I have never felt comfortable with the process, but nonetheless it did work....
5
by: huzz | last post by:
I am trying to create instance of class and and call a method of this class that creates a global variable which is available in anywhere in the page.. Here is what i am doing.. but i am getting...
4
by: ST | last post by:
From Form1 I call a public sub in a module. The sub writes on Form1. Problem: the call creates a new Form1 and writes on it, instead of writing on the one already shown Form1. I have tried to...
13
by: santosh | last post by:
Hi, If I call free() with a uninitialised pointer, will the program state become undefined, or will free() return harmlessly? Incidentally, is there a way in Standard C to determine weather a...
0
by: Przemysław Bana¶ | last post by:
Hello! Can anyone help me with calling Novell function from dll? I think my main problem is in translating C variable types to C# types. Here is the code: using System; using...
5
by: joeblast | last post by:
I have a Web service that gets the financial periods and hold a reference to a disconnected dataset built at initialization. Web methods work on the dataset inside the web service. Everything is...
8
by: Jeff | last post by:
Still new to vb.net in VS2005 web developer... What is the proper/standard way of doing the following - setting the value of a variable in one sub and calling it from another? E.g., as below....
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.