Some guidance

Discussion in 'C++' started by sidaf, Jun 22, 2006.

  1. sidaf

    sidaf Guest

    Hello,

    I've a background in Java programming but I've just started to code a
    bit in C++. I've come across some things in other developers code which
    have confused me a bit. I'm hoping somebody here can clarify the
    following code for me.

    Snippet 1:
    class Foo : public Bar {
    ...
    Foo::Somefunction()
    ...
    if (bytesread <= 0) {
    // Close the connection
    ::close(fd);
    i = clients.erase(i);
    continue;
    }
    ...
    }
    ...
    }

    I thought that the ::close(fd) function called another function defined
    in Foo, but there's no function with that name defined, then I thought
    it must be in Bar, but still no sign. What does the :: point to?

    Sometimes I see functions written as followed:

    SomeObject::SomeFunction() {
    ....
    }

    and then some written like this:

    OtherObject::OtherFunction() {
    ....
    };

    What does the ; at the end mean?

    Thanks,

    Sidaf
     
    sidaf, Jun 22, 2006
    #1
    1. Advertising

  2. sidaf wrote:
    > I've a background in Java programming but I've just started to code a
    > bit in C++. I've come across some things in other developers code
    > which have confused me a bit. I'm hoping somebody here can clarify the
    > following code for me.
    >
    > Snippet 1:
    > class Foo : public Bar {
    > ...
    > Foo::Somefunction()
    > ...
    > if (bytesread <= 0) {
    > // Close the connection
    > ::close(fd);
    > i = clients.erase(i);
    > continue;
    > }
    > ...
    > }
    > ...
    > }
    >
    > I thought that the ::close(fd) function called another function
    > defined in Foo, but there's no function with that name defined, then
    > I thought it must be in Bar, but still no sign. What does the ::
    > point to?


    Global namespace. 'close' is looked up in the global namespace. And
    if there _is_ 'close' member in 'Foo' or 'Bar', it would be *ignored*.

    > Sometimes I see functions written as followed:
    >
    > SomeObject::SomeFunction() {
    > ...
    > }
    >
    > and then some written like this:
    >
    > OtherObject::OtherFunction() {
    > ...
    > };
    >
    > What does the ; at the end mean?


    Usually means the programmer is sloppy.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Jun 22, 2006
    #2
    1. Advertising

  3. sidaf

    sidaf Guest

    Victor Bazarov wrote:
    > Global namespace. 'close' is looked up in the global namespace. And
    > if there _is_ 'close' member in 'Foo' or 'Bar', it would be *ignored*.
    >
    > > Sometimes I see functions written as followed:
    > >
    > > SomeObject::SomeFunction() {
    > > ...
    > > }
    > >
    > > and then some written like this:
    > >
    > > OtherObject::OtherFunction() {
    > > ...
    > > };
    > >
    > > What does the ; at the end mean?

    >
    > Usually means the programmer is sloppy.
    >
    > V
    > --
    > Please remove capital 'A's when replying by e-mail
    > I do not respond to top-posted replies, please don't ask


    Ahh ok, thanks for your help.

    Sidaf
     
    sidaf, Jun 22, 2006
    #3
  4. sidaf wrote:
    > ...
    > Sometimes I see functions written as followed:
    >
    > SomeObject::SomeFunction() {
    > ...
    > }
    >
    > and then some written like this:
    >
    > OtherObject::OtherFunction() {
    > ...
    > };
    >
    > What does the ; at the end mean?
    > ...


    Nothing. Moreover, since these are out-of-class member function
    definitions, this ';' is simply illegal (although most compilers seem to
    allow it).

    --
    Best regards,
    Andrey Tarasevich
     
    Andrey Tarasevich, Jun 22, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brendan Duffy
    Replies:
    0
    Views:
    4,746
    Brendan Duffy
    Jul 25, 2003
  2. luna
    Replies:
    3
    Views:
    528
  3. bostonmegarocker

    Some guidance needed

    bostonmegarocker, Jun 30, 2003, in forum: C++
    Replies:
    2
    Views:
    395
    bostonmegarocker
    Jul 1, 2003
  4. Dfenestr8
    Replies:
    2
    Views:
    383
    Sandy Norton
    Jul 4, 2003
  5. Some guidance

    , Dec 4, 2006, in forum: Java
    Replies:
    2
    Views:
    395
Loading...

Share This Page