944,161 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 352
  • C++ RSS
Oct 2nd, 2009
0

Curious working with objects

Expand Post »
cpp Syntax (Toggle Plain Text)
  1. struct Table
  2. {
  3. char* aTag;
  4. char* bTag;
  5. };
  6. int main()
  7. {
  8. Table T1;
  9. cout<<T1.aTag;
  10. cout<<T1.bTag;
  11. return 0;
  12. }

This might be crazy but... i really need to know
is there any way to so that we can only write
cpp Syntax (Toggle Plain Text)
  1. cout<<aTag
  2. cout<<bTag
instead of T1.aTag like we do in namespace by using namespace <something> for a block.
Can in be done for pointers T1->aTag .
I tried something but have to write each of them for different object...
Last edited by Rhohitman; Oct 2nd, 2009 at 6:20 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
Rhohitman is offline Offline
81 posts
since Dec 2007
Oct 2nd, 2009
0

Re: Curious working with objects

Why ?

Maybe something like this :

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using std::cout;
  5. using std::string;
  6. using std::endl;
  7.  
  8. namespace Curious
  9. {
  10. string mystery = "Magic";
  11.  
  12. struct Wonder
  13. {
  14. Wonder(string msg) { mystery = msg; }
  15.  
  16. };
  17. }
  18. int main()
  19. {
  20. using namespace Curious;
  21.  
  22. cout<<mystery<<endl;
  23. Wonder why("What is going on ? ");
  24. cout << mystery << endl;
  25.  
  26.  
  27. return 0;
  28. }
Reputation Points: 840
Solved Threads: 594
Senior Poster
firstPerson is offline Offline
3,865 posts
since Dec 2008
Oct 2nd, 2009
0

Re: Curious working with objects

you are just changing the string ... which is not the member variable.. itself and printing ... its funny...
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
Rhohitman is offline Offline
81 posts
since Dec 2007
Oct 2nd, 2009
0

Re: Curious working with objects

Take a look at this thread. I think this is what you are looking for.
Reputation Points: 164
Solved Threads: 98
Practically a Master Poster
sfuo is offline Offline
642 posts
since Jul 2009
Oct 2nd, 2009
0

Re: Curious working with objects

Click to Expand / Collapse  Quote originally posted by Rhohitman ...
you are just changing the string ... which is not the member variable.. itself and printing ... its funny...
Well the idea was to use the string, inside the struct as if it was
a member.
Reputation Points: 840
Solved Threads: 594
Senior Poster
firstPerson is offline Offline
3,865 posts
since Dec 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: vector help
Next Thread in C++ Forum Timeline: Convert Decimal to any base





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC