Solved

Object  problem

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SendMessage fails while PostMessage works 2 107
PDF library for Delphi 2 103
Writing a parser for java language 4 71
How to convert MFC::CString to UTF8 wchar_t* 10 137
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

939 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

10 Experts available now in Live!

Get 1:1 Help Now