Solved

Object  problem

Posted on 2000-04-27
2
168 Views
Last Modified: 2010-04-02
Hi all
        i have two files in two .cpp files i'm using one object of same class type..my problem is i want to allocate  same memory location for two objects in two files..if i work with one object i have to access the same with other object in other file..
  i mean both object's  should  contain same thing...

thanks for answer

Suneel
0
Comment
Question by:chowdary010899
2 Comments
 
LVL 1

Expert Comment

by:mahno
ID: 2758479
Allocate memory once and work via pointer
0
 
LVL 22

Accepted Solution

by:
nietod earned 20 total points
ID: 2759034
You can declare the object as a global varaible and then use it from both files.  One file must declare and define the object.   like

SomeClass ObjectName;

Then any other file that wishes to also use the object needs to declare the object as an external, like

extern SomeClass ObjectName;

Then that file can then use the object.   If there are many files that need to use the object, you could place the external declaration in an .h file and include it into all the files.  (you could even include it into the file that has the object's definition, it won't cause a problem.)

Let me know if you have any questions.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now