473,325 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

object accessing

38
hi all,

i have some trouble to figure out how can i access the object like in this case
Expand|Select|Wrap|Line Numbers
  1. //file1.h
  2. class T1{
  3. T1();
  4. ~T1();
  5. ....
  6. };
  7. ====
  8. //file2.h
  9. #include file1.h
  10. class T2{
  11. T2();
  12. ~T2();
  13.  
  14. T1 Test;   // consider this object
  15.  
  16. mem_foo() // member function
  17. ....
  18. };
  19. =====
  20. //file2.cpp
  21. ...
  22. T2::mem_foo(){
  23. foo();   //   this function is declared in file1.h
  24. }
  25. =====
  26. //file3.h
  27. extern foo();
  28. ====
  29. //file3.cpp
  30. foo()
  31. {
  32. // here is my problem! how can i access the object "Test" 
  33. //which is declared  in file2 in such case????
  34. }
  35.  
P.S. i have tried to simplify the code to just consider the on the main problem. Also, this code is not compilable.


thanks for each suggestion
Nov 21 '09 #1
4 1402
Banfa
9,065 Expert Mod 8TB
You can't access .Test in foo unless you make foo a member of T2 or pass a reference or pointer to the T2 object into foo.

I think a pertanent question here is why can't foo be a member of T2?
Nov 21 '09 #2
whodgson
542 512MB
Also you appear to be attempting to create the object Test within the T2 class which would normally occur in main().
Nov 22 '09 #3
mar11
38
@banfa;
you may need this approach of accessing the object "Test" if you got the the function foo() from the file3.h as an interface function. In this case you are not allowed to change the name or declare it somewhere else....

In this case how can you deal with it. i hope my question is getting through now. Again, i have to treat the foo() function in the file3.h as interface function.

form you experience, may you lead me to the right way :) ?
Nov 22 '09 #4
Banfa
9,065 Expert Mod 8TB
You are saying that you can change the contents of the function foo() but not the prototype?

In that case you need another function that you can call that will return the instance of T2 to use. This could be a function you call which takes some identifying parameter and looks up the object in an object store or it could be a singleton instance accessor (singleton design pattern).

Alternatively if the instance of T2 only needs to last for the lifetime of the function construct it in foo().

TBH the details of your problem are a little hazy as you haven't actually said what the function foo() is tying to achieve.
Nov 22 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: WhyteWolf | last post by:
I'm trying to set a object as global for access through out the rest of my script ... {a basic SQL accessing object} however if I try calling the object from with in another object it acts as if it...
6
by: Luke | last post by:
Here is my emails to Danny Goodman (but probably he is very busy so he didn't answered it). First email(simple): Subject: JavaScript Arrays " We all know the array can act like HashMap, but is...
3
by: Alex | last post by:
I'm having a problem porting an ASP solution to ASPX. In the ASP solution I'm accessing a DCOM server, create sub DCOM objects and call functions from VB script on the ASP pages. The DCOM object...
7
by: J-T | last post by:
I can instantiate my object in my *ASP.NET* application in two ways: A) public sealed class RSSingleton { private static ReportingServiceProxy m_RsProxy=null; static RSSingleton() {...
4
by: lars.uffmann | last post by:
Hey everyone! I am (still) working on a project that I took over from former students, so don't blame me for the criminal approach on coding *g* The problem I have is fairly easy and while I...
26
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized...
4
by: gg9h0st | last post by:
i'm a newbie studying php. i was into array part on tutorial and it says i'll get an array having keys that from member variable's name by converting an object to array. i guessed "i can...
12
by: better_cs_now | last post by:
Hello all, I suspect that a threading issue is leading to an object being destructed in one thread context while one of its member functions is still running in another thread context. As a...
7
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I access a property of an object using a string?...
0
by: Roger Stoller | last post by:
Hello. I have developed a COM object using ATL. It seems to work fine when accessing it from VB.NET most of the time. However, I want to use a delegate in VB to asynchronously run a method in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.