[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Object  problem

Posted on 2000-04-27
2
Medium Priority
?
216 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
[X]
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
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

656 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