Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

C++ Member Function Lookup

Name: Anonymous 2010-02-06 12:22

I'm reading `C++ Common Knowledge' to find out more about this fascinating pile of crap. I'm currently in the section `Member Function Lookup' and discovered this gem:

class Foo {
public:
        void x(int) {}
};

class Bar : Foo {
        int x; /* This is fuckin' private. */
};

int main()
{
        Bar bar;
        bar.x(3);
        return 0;
}


I understand what it does and why it does it, but what the fuck was Bjarne thinking when he decided this? If this is object-oriented programming, I'm Ada Lovelace. HIBT?

Name: Anonymous 2010-02-06 12:26

But what the fuck was Bjarne thinking when he decided this?

``This seems to be a great idea! Indeed, I am smart, moreover, I am a genius. I will proceed to masturbate.''

Name: Anonymous 2010-02-06 12:44

LOVELACE MY ANUS

Name: Anonymous 2010-02-06 12:55

What the fuck are you thinking, giving a variable the same name as a function?

Name: Anonymous 2010-02-06 13:15

It may be confusing, but it shouldn't matter if you separate the function and variable namespaces. Lisp-2's (like CL) do this well:
#'function-name == (function function-name)
variable-name
(function-name variable-name)

(defun list-of-list (list)
  (list list))

Name: Anonymous 2010-02-06 13:38

>>4
There are two severe problems with the approach C++ is taking: first of all, Bar's x is private. I, by their very definition, shouldn't need to be concerned about members I can't see. Even if it was public, the right thing would be to realize that `int x' doesn't match the required signature for `bar.x(3)' and continue the search to the base classes.
>>5
OH RLY? funcall my anus.

Name: Anonymous 2010-02-06 14:49

>>6
Why not replace funcall with a special symbol via reader macro, then? The only thing special about funcall is that it requires the function to be passed in the variable namespace.

Name: Anonymous 2010-02-06 15:03

>>7
Did you notice that this thread is not about Common Lisp? It is about C++. I know how to deal with funcall the way I want. >>5 was the one who brought CL into this thread.

Name: Anonymous 2010-02-06 16:10

>>5
Why stop at 2? Why not let every little trivial type in your language have its own namespace? That'd really clean things up.

Name: Anonymous 2010-02-06 16:22

>>6
That doesn't answer my question. Why would you ever need to give a variable the same name as a function? Why don't you complain about things that actually matter, rather than this trivial bullshit nobody could care less about?

Name: Anonymous 2010-02-06 16:28

>>9
That's why it's actually called a Lisp-n.

Name: Anonymous 2010-02-06 16:35

>>10
Okay, let's rephrase it:
class Foo {
public:
        void x(int) {}
};

class Bar : Foo {
        void x() {} /* This is still fuckin' private. */
};

int main()
{
        Bar bar;
        bar.x(3);
        return 0;
}

Will you shut up now?

Name: Anonymous 2010-02-06 16:42

I'm not sure what this thread is going on about, but it's been worth twelve posts so far.

Name: Anonymous 2010-02-06 16:43

>>10
I don't know about C++, but I actually (ab)use the fact that there's a separate namespace for functions and variables in CL (well, there's also the package system which allows for even better control). For example, I almost always use "list" as a name for an argument representing a list on a function that's meant to just do some generic operation on lists. At the same time, "list" is also a function which just conses up a list. In Scheme and Lisp-1's, where there is a single namespace, people just name such arguments "lst"/"lyst" or similar to avoid shadowing the "list" function.

Name: Anonymous 2010-02-06 16:45

>>14
Lyst! Lyst! burning bright
In the forests of the night,
What immortal hand or eye
Could frame thy fearful symmetry?
In what distant deeps or skies
Burnt the fire of thine eyes?
On what wings dare he aspire?
What the hand dare sieze the fire?
And what shoulder, & what art.
Could twist the sinews of thy heart?
And when thy heart began to beat,
What dread hand? & what dread feet?
What the hammer? what the chain?
In what furnace was thy brain?
What the anvil? what dread grasp
Dare its deadly terrors clasp?
When the stars threw down their spears,
And watered heaven with their tears,
Did he smile his work to see?
Did he who made the Lamb make thee?
Lyst! Lyst! burning bright
In the forests of the night,
What immortal hand or eye
Dare frame thy fearful symmetry?

Name: Anonymous 2010-02-06 17:28

>>10
I could care less.

Name: Anonymous 2010-02-06 19:45

>>16
Then by all means, do.

Name: Anonymous 2010-02-06 21:28

>>1
Of all the things in C++, this seems like a really *good* idea to me. Why would you want your subclass to be affected by private variables in the base class that you know nothing about?

Name: Anonymous 2010-02-06 23:02

There's a reason why Sepplesix is bringing in inheritance specifiers to clarify your intent. Unfortunately, they're ugly as fuck, so it's unlikely that they'll find a great deal of use.

Name: Anonymous 2010-02-06 23:02

you stupid fuck, learn to fucking use fucking C++ class hierarchies..bitch...cut ur self and die

Name: Anonymous 2010-02-07 2:08

>>18
What do you mean? The base class function is public and the one in the subclass is private, which I know nothing about. Still it blocks my way to the base class.

Name: Anonymous 2010-02-07 2:12

>>20
You mad?

Name: Anonymous 2010-02-07 5:15

>>22
NO, U MAD

Name: Anonymous 2010-02-07 6:39

Breaking news: clarity of semi-OOP language compromised because of gimped message-passing clone! More at twelve!

Name: Anonymous 2010-02-07 6:41

>>21
Oh wait, I misread the original posting; I thought Foo extended Bar, not the other way around. I actually tried to compile the thing now and I get what you're saying. Sorry, >>18 retracted; just another thing to hate about sepples I guess.

Name: Anonymous 2010-02-07 11:42

I don't really get this thread, but neither >>1 or >>12 compile under GCC.

Name: Anonymous 2010-02-07 11:43

>>26

you mena g++?

Name: Anonymous 2010-02-07 11:45

>>27
wow that was fast, but sure

Name: Anonymous 2010-02-07 12:02

>>28
That's what SHE said.

Name: Anonymous 2010-02-07 12:56

>>29
Back to [i]/r9k/[i], Randall.

Name: SMALLTALKER 2010-02-07 14:10

Of course Bjarne was wrong, but was it intentional?  Public instance variable are a heresy in first place. Everytime g++ spits you three pages of arcane STL errors, it's like the Stroustrup is slapping his limp dick as your face. Cunning, cunningBjarne.

Name: Anonymous 2010-02-07 14:59

>>26
That is the point of this thread.

Name: Anonymous 2011-02-03 3:32

Name: Anonymous 2011-02-04 12:40

Name: Anonymous 2011-02-04 17:54


Don't change these.
Name: Email:
Entire Thread Thread List