Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Object  problem

Posted on 2000-04-27
2
Medium Priority
?
218 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 80 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

810 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