Some guidance

S

sidaf

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
 
V

Victor Bazarov

sidaf said:
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
 
S

sidaf

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


Usually means the programmer is sloppy.

V

Ahh ok, thanks for your help.

Sidaf
 
A

Andrey Tarasevich

sidaf said:
...
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).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top