Hello,
I'm confused by the use of the Scope resolution operator on the
indicated lines in the following code (which was copied from Thinking in
C++ by Bruce Eckel). Removing them seems to have no effect.
//Begin Code
#include <new> // Size_t definition
#include <fstream>
using namespace std;
class Widget {
enum { sz = 10 };
int i[sz];
public:
Widget() { }
~Widget() { }
void* operator new(size_t sz) {
return ::new char[sz]; //I'm confused here
}
void operator delete(void* p) {
::delete []p; //and here
}
void* operator new[](size_t sz) {
return ::new char[sz];// and here
}
void operator delete[](void* p) {
::delete []p; //yup, here as well.
}
};
int main() { }
//END Code
Thanks in advance for any replies!
-exits 5 2656
"exits funnel" <ex*********@NO SPAMyahoo.com> wrote... I'm confused by the use of the Scope resolution operator on the indicated lines in the following code (which was copied from Thinking in C++ by Bruce Eckel). Removing them seems to have no effect.
It's an indicator (if nothing else) that the function used will
be from the global namespace. This code illustrates the use of
the name resolution that actually changes the behaviour of the
program:
int foo(int) {
return 42;
}
struct bar {
int foo(int a) {
return ::foo(a + 1); // remove the '::' and you have
// infinite recursion
}
};
int main() {
bar b;
b.foo(13); // step into this function in debugger to see
// which one is called when
} //Begin Code #include <new> // Size_t definition #include <fstream> using namespace std;
class Widget { enum { sz = 10 }; int i[sz]; public: Widget() { } ~Widget() { } void* operator new(size_t sz) { return ::new char[sz]; //I'm confused here } void operator delete(void* p) { ::delete []p; //and here } void* operator new[](size_t sz) { return ::new char[sz];// and here } void operator delete[](void* p) { ::delete []p; //yup, here as well. } }; int main() { } //END Code
Thanks in advance for any replies!
-exits
On Fri, 12 Dec 2003 04:56:58 GMT, exits funnel
<ex*********@NO SPAMyahoo.com> wrote: Hello,
I'm confused by the use of the Scope resolution operator on the
There's no such thing as a 'scope resolution operator'.
indicated lines in the following code (which was copied from Thinking in C++ by Bruce Eckel). Removing them seems to have no effect.
You haven't used Widget, that's why there's no effect. Try using it
and you'll see.... //Begin Code #include <new> // Size_t definition #include <fstream> using namespace std;
class Widget { enum { sz = 10 }; int i[sz]; public: Widget() { } ~Widget() { } void* operator new(size_t sz) { return ::new char[sz]; //I'm confused here } void operator delete(void* p) { ::delete []p; //and here } void* operator new[](size_t sz) { return ::new char[sz];// and here } void operator delete[](void* p) { ::delete []p; //yup, here as well. } }; int main() { } //END Code
Thanks in advance for any replies!
-exits
>There's no such thing as a 'scope resolution operator'.
Doh! I read 'scope resolution' but thought 'overload resolution'...
I need some sleep. Good night!
"exits funnel" <ex*********@NO SPAMyahoo.com> wrote in message
news:3F******** ******@NOSPAMya hoo.com... Hello,
I'm confused by the use of the Scope resolution operator on the indicated lines in the following code (which was copied from Thinking in C++ by Bruce Eckel). Removing them seems to have no effect.
//Begin Code #include <new> // Size_t definition #include <fstream> using namespace std;
class Widget { enum { sz = 10 }; int i[sz]; public: Widget() { } ~Widget() { } void* operator new(size_t sz) { return ::new char[sz]; //I'm confused here } void operator delete(void* p) { ::delete []p; //and here } void* operator new[](size_t sz) { return ::new char[sz];// and here } void operator delete[](void* p) { ::delete []p; //yup, here as well. } }; int main() { }
I think it has no effect because you've just compiled that code. You
haven't actually called new. I imagine it would be a recursive function,
such as:
void f()
{
f();
}
int main()
{
f();
}
Try running that and see how it goes!
Thank you Victor, this clear it up nicely.
-exits
Victor Bazarov wrote: "exits funnel" <ex*********@NO SPAMyahoo.com> wrote...
I'm confused by the use of the Scope resolution operator on the indicated lines in the following code (which was copied from Thinking in C++ by Bruce Eckel). Removing them seems to have no effect.
It's an indicator (if nothing else) that the function used will be from the global namespace. This code illustrates the use of the name resolution that actually changes the behaviour of the program:
int foo(int) { return 42; }
struct bar { int foo(int a) { return ::foo(a + 1); // remove the '::' and you have // infinite recursion } };
int main() { bar b; b.foo(13); // step into this function in debugger to see // which one is called when }
//Begin Code #include <new> // Size_t definition #include <fstream> using namespace std;
class Widget { enum { sz = 10 }; int i[sz]; public: Widget() { } ~Widget() { } void* operator new(size_t sz) { return ::new char[sz]; //I'm confused here } void operator delete(void* p) { ::delete []p; //and here } void* operator new[](size_t sz) { return ::new char[sz];// and here } void operator delete[](void* p) { ::delete []p; //yup, here as well. } }; int main() { } //END Code
Thanks in advance for any replies!
-exits This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Anonymous |
last post by:
Is namespace the same thing as scope? While reading the book
"Thinking in C++", I was under the impression that namespace is, well,
a namespace--a feature to create a hiearchy for identifiers within the
Global Namespace. And that, all identifiers within a given namespace,
however deeply nested they are, each of them has the Global Scope.
So, if
namespace outer {
int a = 1;
|
by: Richard Hayden |
last post by:
Hi,
I have the following code for example:
/**********************************/
#include <iostream>
class C1 {
public:
|
by: Howard Gardner |
last post by:
/*
I don't have to provide scope resolution in sit 0 below: adl
finds the function that I mean to use.
I do have to provide scope resolution in sits 1 and 2.
Can anyone teach me a trick to get around the need for scope resolution
in sit 1 or sit 2?
sit 1 is my motivating case, but if there's a trick for sit 2 I'd like
|
by: richard pickworth |
last post by:
Hello :)
I am familiar with using scope resolution operator to define classes, but
why does it turn up elsewhere?
thanks
richard
|
by: sushant |
last post by:
hi ,
can we use scope resolution operator (::) in C???
sushant
| |
by: Jack |
last post by:
I want to write code that can be compiled as C and C++. In the Windows
API, there are many macros that help with scope resolution. For
example:
#ifdef __cplusplus
#define SNDMSG ::SendMessage
#else
#define SNDMSG SendMessage
#endif
|
by: Steven T. Hatton |
last post by:
All of the following terms are used in some way to describe where and how a
name is relevant to a particular location in a program: visible,
declarative region, scope, potential scope, valid, introduced, used,
potentially evaluated and accessible. They all seem to have subtle
difference in meanings.
Any positive contribution to the following will be appreciated.
Here is my attempt to make sense of these:
|
by: xtrigger303 |
last post by:
Hi to all,
I was reading Mr. Alexandrescu's mojo article and I've a hard time
understanding the following.
Let's suppose I have:
//code
struct A {};
struct B : A {};
|
by: Shan |
last post by:
In the following code:
func()
{
int SmeVar;
{
int SmeVar;
//Here I want to use SmeVar defined in the outer block how
can I do that ?
}
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |