By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 802 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

Some guidance

P: n/a
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

Jun 22 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
Jun 22 '06 #2

P: n/a

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

Jun 22 '06 #3

P: n/a
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
Jun 22 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.