473,388 Members | 1,330 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,388 software developers and data experts.

scope resolution operator

Hello :)
I am familiar with using scope resolution operator to define classes, but
why does it turn up elsewhere?
thanks
richard
Jul 23 '05 #1
3 4388
richard pickworth wrote:
I am familiar with using scope resolution operator to define classes, but
why does it turn up elsewhere?


Where? Namespaces?

Jul 23 '05 #2
On 2005-06-05, richard pickworth <ri***************@btopenworld.com> wrote:
Hello :)
I am familiar with using scope resolution operator to define classes, but
why does it turn up elsewhere?
thanks


A few I can think of:
(1) to call a static member function
(2) to namespace-qualify something (e.g. std::cout << "hello" << std::endl; )
(3) to explicitly call a base class member function instead of a derived class
override, e.g.
class Base { public: virtual void foo(); .... }
class Derived : public Base {
public:
virtual void foo() {
Base::foo();
// do other stuff
}
};

(4) to provide visibility for otherwise hidden methods via using (see the FAQ)
e.g.
class Base { public: void foo();
}
class Derived {
public:
void foo(int ); // hides base class version
using Base::foo; // make it visible
};

that's all I can think of off the top of my head, but there could well be
others I've left out.

Cheers,
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/
Jul 23 '05 #3
do you mean "static member function" i.e. as opposed to dynamicaly
allocated?
I thought you would use "class.function()".
Dynamicaly, I thought maybe "class->function".
Explicitly call a base class member function - that would fit with "scope
resolution" maybe.
I like your example on visibility. Do "virtual" functions belong in such
situations, or similar? (I'm still trying to figure out polymorphism).
using - I'm not familiar with this, except maybe "using namespace". I'll
check out the FAQ if I can.
Cheers
Richard
"Donovan Rebbechi" <ab***@aol.com> wrote in message
news:sl******************@panix2.panix.com...
On 2005-06-05, richard pickworth <ri***************@btopenworld.com>
wrote:
Hello :)
I am familiar with using scope resolution operator to define classes, but
why does it turn up elsewhere?
thanks


A few I can think of:
(1) to call a static member function
(2) to namespace-qualify something (e.g. std::cout << "hello" <<
std::endl; )
(3) to explicitly call a base class member function instead of a derived
class
override, e.g.
class Base { public: virtual void foo(); .... }
class Derived : public Base {
public:
virtual void foo() {
Base::foo();
// do other stuff
}
};

(4) to provide visibility for otherwise hidden methods via using (see the
FAQ)
e.g.
class Base { public: void foo();
}
class Derived {
public:
void foo(int ); // hides base class version
using Base::foo; // make it visible
};

that's all I can think of off the top of my head, but there could well be
others I've left out.

Cheers,
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/

Aug 8 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
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...
5
by: exits funnel | last post by:
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...
7
by: Richard Hayden | last post by:
Hi, I have the following code for example: /**********************************/ #include <iostream> class C1 { public:
0
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...
16
by: sushant | last post by:
hi , can we use scope resolution operator (::) in C??? sushant
6
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...
4
by: heng | last post by:
A::B I can understand that B is a member of the scope A But, sometimes I read the expression like ::C, what does this mean when the scope is absent? Thanks.
2
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 {};
5
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 ? }
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.