954,123 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Curious working with objects

struct Table
{
char* aTag;
char* bTag;
};
int main()
{
Table T1;
cout<<T1.aTag;
cout<<T1.bTag;
return 0;
}


This might be crazy but... i really need to know
is there any way to so that we can only write

cout<<aTag 
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...

Rhohitman
Junior Poster in Training
83 posts since Dec 2007
Reputation Points: 10
Solved Threads: 5
 

Why ?

Maybe something like this :

#include <iostream>
#include <string> 
 
using std::cout;
using std::string;
using std::endl;

namespace Curious
{
	string mystery = "Magic";

	struct Wonder
	{
		Wonder(string msg) { mystery = msg; }

	};
}
int main()
{  
	using namespace Curious;

	cout<<mystery<<endl;
	Wonder why("What is going on ? ");
	cout << mystery << endl;
 

	return 0;
}
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
 

you are just changing the string ... which is not the member variable.. itself and printing ... its funny... :P

Rhohitman
Junior Poster in Training
83 posts since Dec 2007
Reputation Points: 10
Solved Threads: 5
 

Take a look at this thread . I think this is what you are looking for.

sfuo
Practically a Master Poster
655 posts since Jul 2009
Reputation Points: 164
Solved Threads: 99
 
you are just changing the string ... which is not the member variable.. itself and printing ... its funny... :P

Well the idea was to use the string, inside the struct as if it was
a member.

firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You