Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Object  problem

Posted on 2000-04-27
2
193 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

839 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