Newbie Q: What does ::fn() mean? 
Author Message
 Newbie Q: What does ::fn() mean?

I'm in a "programmer quit & so I've got to pickup the slack" mode here.
I've got some books on C++, just haven't seen this yet.

I've seen in examples where a class with a base class
class derived : class base;

has a call to the original class in a function:
int derived::somebasefn()
{
    dosomething;
    base::somebasefn();

Quote:
}

but what does it mean when I don't see the base class?

i.e.,  return (::Whatever(x,y,z));

Is this also a base class function, but it doesn't need class specifying
because it's not the same function, or something else?
For example, I've seen calls to ::CreateThread() in the code I've
"inherited"!

THanks in advance,
Dirk Taylor



Tue, 25 Feb 2003 21:48:18 GMT  
 Newbie Q: What does ::fn() mean?

Greets,

    The scope resolution operator provided as "::" without a class or
namespace name just says: "Use this function or global in the global
namespace".  This is useful in cases where one person may be using MFC, and
a meber function of the class is the same of that as the Win32 API function
(for example, BitBlt() in the CDC class) but one wishes to use the Win32 API
BitBlt() instead from within the class.

Regards,

Joe


Quote:
> I'm in a "programmer quit & so I've got to pickup the slack" mode here.
> I've got some books on C++, just haven't seen this yet.

> I've seen in examples where a class with a base class
> class derived : class base;

> has a call to the original class in a function:
> int derived::somebasefn()
> {
>     dosomething;
>     base::somebasefn();
> }

> but what does it mean when I don't see the base class?

> i.e.,  return (::Whatever(x,y,z));

> Is this also a base class function, but it doesn't need class specifying
> because it's not the same function, or something else?
> For example, I've seen calls to ::CreateThread() in the code I've
> "inherited"!

> THanks in advance,
> Dirk Taylor



Tue, 25 Feb 2003 21:55:44 GMT  
 Newbie Q: What does ::fn() mean?

Dirk:

When you see

return (::Whatever(x,y,z));

it means that the function Whatever() is a global function, not a class
member function. The :: is not actually necessary, UNLESS the class you
are in also has a function called Whatever() (perhaps with different
signature), but using the :: is a good programming practice.

HTH,

David Wilkinson

===============

Quote:

> I'm in a "programmer quit & so I've got to pickup the slack" mode here.
> I've got some books on C++, just haven't seen this yet.

> I've seen in examples where a class with a base class
> class derived : class base;

> has a call to the original class in a function:
> int derived::somebasefn()
> {
>     dosomething;
>     base::somebasefn();
> }

> but what does it mean when I don't see the base class?

> i.e.,  return (::Whatever(x,y,z));

> Is this also a base class function, but it doesn't need class specifying
> because it's not the same function, or something else?
> For example, I've seen calls to ::CreateThread() in the code I've
> "inherited"!

> THanks in advance,
> Dirk Taylor



Tue, 25 Feb 2003 22:07:48 GMT  
 Newbie Q: What does ::fn() mean?

Thanks.  I think I Got it.

So...what does global namespace mean?
I haven't used this yet, however I've seen some stuff in the mfc or atl?
specifying a namespace.
If it's not too much to ask...
(In Ivor Horton's Beginning C++)
It looks kinda like a namespace is like a class or struct declaration.
Is this a good analogy?  So therefore I'm "dereferencing" a ("class")
namespace with ::, (as opposed to dereferencing an class object with ->  ;-)
correct?
To further this analogy, the global namespace would be like my "this" inside
a class?

Thanks again in advance,
Dirk

Quote:

>Greets,

>    The scope resolution operator provided as "::" without a class or
>namespace name just says: "Use this function or global in the global
>namespace".  This is useful in cases where one person may be using MFC, and
>a meber function of the class is the same of that as the Win32 API function
>(for example, BitBlt() in the CDC class) but one wishes to use the Win32
API
>BitBlt() instead from within the class.

>Regards,

>Joe



Tue, 25 Feb 2003 22:33:57 GMT  
 Newbie Q: What does ::fn() mean?
Thanks David!

Please see my reply to Joe and comment if y'd like.
I just "replied" there but yer comments helped.

Thanks again

Quote:

>Dirk:

>When you see

>return (::Whatever(x,y,z));

>it means that the function Whatever() is a global function, not a class
>member function. The :: is not actually necessary, UNLESS the class you
>are in also has a function called Whatever() (perhaps with different
>signature), but using the :: is a good programming practice.

>HTH,

>David Wilkinson



Tue, 25 Feb 2003 22:36:18 GMT  
 Newbie Q: What does ::fn() mean?
Greets,

    Consider this (horrible and contrived) example:

----------

int MyValue=10;

int MyFunction(int x)
{
    return(x*2);

Quote:
}

class CMyClass {
public:
    int MyValue;
public:
    CMyClass()
    {
        MyValue=20;
    }
    int MyFunction(void)
    {
        return(::MyFunction(::MyValue));
    }

Quote:
};

int main(void)
{
    CMyClass x;

    int j=x.MyFunction();

    return(0);

Quote:
}

------------

    If you remove the scope resolution operator from the call to
MyFunction() from within the member MyFunction(), you'll get a compile
error.  Also, note that you will get a different result for 'j' if you
remove the scope resolution operator from the "MyValue" variable.  I'll
leave it as an excercise for you to see it in action.  :)

Regards,

Joe


Quote:
> Thanks.  I think I Got it.

> So...what does global namespace mean?
> I haven't used this yet, however I've seen some stuff in the mfc or atl?
> specifying a namespace.
> If it's not too much to ask...
> (In Ivor Horton's Beginning C++)
> It looks kinda like a namespace is like a class or struct declaration.
> Is this a good analogy?  So therefore I'm "dereferencing" a ("class")
> namespace with ::, (as opposed to dereferencing an class object with ->
;-)
> correct?
> To further this analogy, the global namespace would be like my "this"
inside
> a class?

> Thanks again in advance,
> Dirk


> >Greets,

> >    The scope resolution operator provided as "::" without a class or
> >namespace name just says: "Use this function or global in the global
> >namespace".  This is useful in cases where one person may be using MFC,
and
> >a meber function of the class is the same of that as the Win32 API
function
> >(for example, BitBlt() in the CDC class) but one wishes to use the Win32
> API
> >BitBlt() instead from within the class.

> >Regards,

> >Joe



Tue, 25 Feb 2003 23:06:23 GMT  
 Newbie Q: What does ::fn() mean?

Excellent!
Thanks.

So, does this mean this...

namespace dummy
{
int MyValue=5;
int MyFunction(int x) {    return(x\2); }

Quote:
}

int MyValue=10;
int MyFunction(int x) {    return(x*2); }

int main(void) {
    int j=::MyFunction(dummy::Myvalue);
    int k=dummy::MyFunction(::Myvalue);

    return(0);

Quote:
}

------------
...is also valid...
(I exclude the class for now...)
...and I'd get the following (before return())
    j=10 & k=5 ?

Eh?
(Contrived is good...)

Finally, since I'm not sure if I know yet, how could I acess these from
another cpp or dll?
I believe I can use extern to indicate something here...I just don't know
all the wonderful permutations/limitations.
would both sets be visible externally?  How far out can this go?
Declarations required? ...

Thanks again!



Tue, 25 Feb 2003 23:29:49 GMT  
 Newbie Q: What does ::fn() mean?



[still more questions about ::, and now about extern]

Dirk, we love questions. But learning C++ by asking the group to
explain each and every feature is not efficient for you or the
group.

Probably the best way to use the group is this. When you find
that a specific detail has you stuck, ask about that.  But for
learning most of the details, what you need is a good book.
Or two or three or four.  Plus some good FAQs.

You want to read the FAQs at these URLs.  Pay
attention to the further books and FAQS they recommend.

The C++ FAQ lite
http://marshall-cline.home.att.net/cpp-faq-lite/
And you really want to get the book version
which is much expanded and more detailed.

A Win32 programming faq
http://www.iseran.com/Win32/FAQ/

An MFC FAQ
http://mfcfaq.stingray.com/

Here is the MVP faq
http://www.mvps.org/vcfaq/

And you should be able to find some good book reviews here.
http://www.accu.org/bookreviews/public/reviews/0sb/index.htm

For coding in Visual C/C++, you want to go through
the tutorials, and read the examples. Start with the
Scribble tutorial.  Probably the books you want to
start with are the one by Petzold and the one by
Prosise.

Read Schaum's outline on C++.  Cheap, quick, easy,
lots of worked examples. Just don't let it be your
last book, because it is by no means even close
to complete. It will help you up the learning curve.

The cannonical reference on the C++ language is
_The C++ Language (3rd Edition)_ by Stroustrup.
(There is now a special edition with some extra
material, and you should probably get this if
you have not already got the 3rd edition.)
If you are planning to be in the industry, you
really want to get and *carefully* read this.

--
Dan Evens
Standard disclaimers etc. No spam please.



Tue, 25 Feb 2003 23:47:41 GMT  
 Newbie Q: What does ::fn() mean?

Okay.
I can appreciate that.
I think my original question helped me look up the right stuff (in my C++
book, which I did.)
I suppose I got carried away, but I defend myself by saying I did prefix by
saying "if it's not too much to ask..."
So, are you saying don't go on and on, or that this is not the appropriate
use of this section (vs.language), or try the FAQ's first?
I haven't actually written many questions yet (but I'm ramping up...)!

FYI:  I saw your list of links in an earlier response and have bookmarked
some of them already.
Thanks for posting them.

Dirk



Wed, 26 Feb 2003 00:23:06 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Qs on newbie code

2. Base::fn(int) is covered by Derived::fn()

3. fn(array) vs. fn(&array)

4. diffrence between fn and member fn

5. varargs fn calling varargs fn?

6. newbie: what does this line mean?

7. Newbie doing professional tasks.

8. Newbie doing dumb things with m_strFilter...please help

9. --- Recap: Qs. about struct ---

10. Qs of getrusage()

11. Qs on Function Call on Array

12. C's Qs

 

 
Powered by phpBB® Forum Software