Solved

Very very easy question

Posted on 2000-05-17
6
175 Views
Last Modified: 2010-04-02
If I have object bigcookie
class cookie{
public:
int chocolatechips;
};
cookie bigcookie;

and a function in a namespace:
namespace foodfuncs{
void bigcookie(void){}
}

If I say 'using foodfuncs' bigcookie thenceforth refers to foodfuncs::bigcookie.

How do I make it refer to the cookie object again? Am I right in thinking it is a compile-time issue, and in the executable, these two entities will have different names?

Thank you
0
Comment
Question by:glebspy
[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
  • 3
  • 2
6 Comments
 

Expert Comment

by:forza
ID: 2818589
>How do I make it refer to the cookie object again?
What do you mean by "again"?
You cannot have the bigcookie func refer to the object. Why would you do that?
0
 
LVL 1

Author Comment

by:glebspy
ID: 2818614
ok I have the above followed by:

void main(void);
cookie bigcookie;
bigcookie.chocolatechips=1;

//Now I use the namespace
using foodfuncs:
bigcookie();

//ok so far so good but now I want to
//be able to say
bigcookie.chocolatechips=3;
//which I can't because thanks to my //using statement bigcookie means
//the function bigcookie

So now I hope you understand the question
thank you
0
 
LVL 1

Author Comment

by:glebspy
ID: 2818624
ok I have the above followed by:

void main(void);
cookie bigcookie;
bigcookie.chocolatechips=1;

//Now I use the namespace
using foodfuncs:
bigcookie();

//ok so far so good but now I want to
//be able to say
bigcookie.chocolatechips=3;
//which I can't because thanks to my //using statement bigcookie means
//the function bigcookie

So now I hope you understand the question
thank you
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Accepted Solution

by:
nietod earned 5 total points
ID: 2818974
Try

::bigcookie.chocolatechips=3;

0
 
LVL 1

Author Comment

by:glebspy
ID: 2819064
I really wanted to know how to reverse the effect of the 'using' statement for good, rather than just that one instance - still I guess its worth 5 points
0
 
LVL 22

Expert Comment

by:nietod
ID: 2819250
>> I really wanted to know how to reverse
>> the effect of the 'using' statement for good
Then you should have asked that.

And you should not have given a bad grade for an answer that was correct, but just not what you wanted--especially since I didn't answer. I would much much rather have not had the points than have a bad grade in my record.

I believe that a using declaration obeys scope rules.  So use it inside a scope and it will not extend outside of that scope.
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

739 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