So it has been proven

G

gwowen

Error 'f' : identifier not found.
What language is this code supposed to be ?.

Here's the original code - I may have messed up when adding the
comments:

#include<iostream>
class A {
public:
int num;
int another_num;
int f() { return num;}
void setnum(int x) {num = x;}
};

int main()
{
int z = 4;
A* foo = reinterpret_cast<A*> (&z);

std::cout << foo->f() << std::endl;
foo->setnum(7);
std::cout << z << std::endl;
}
 
G

gwowen

Here's the original code - I may have messed up when adding the
comments:

Yeah, I did. I copy and pasted the non-member function main(), and
the member function class definition. Oops. So here is the correct
code (again).

#include<iostream>
class A {
public:
int num;
int another_num;
int f() { return num;}
void setnum(int x) {num = x;}
};

int main()
{
int z = 4;
A* foo = reinterpret_cast<A*> (&z);

std::cout << foo->f() << std::endl;
foo->setnum(7);
std::cout << z << std::endl;
}
 
P

Paul

Here's the original code - I may have messed up when adding the
comments:

Yeah, I did. I copy and pasted the non-member function main(), and
the member function class definition. Oops. So here is the correct
code (again).

#include<iostream>
class A {
public:
int num;
int another_num;
int f() { return num;}
void setnum(int x) {num = x;}
};

int main()
{
int z = 4;
A* foo = reinterpret_cast<A*> (&z);

std::cout << foo->f() << std::endl;
foo->setnum(7);

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
5.2.2
"The first expression in the postfix expression is then
called the object expression, and the call
is as a member of the object pointed to or referred to."


Your dereferenced foo is not an A object , its an integer.
You code is not standard compliant C++.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Please not the above quote contains the text: "a member of the object".
 
W

werasm

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
5.2.2
"The first expression in the postfix expression is then
called the object expression, and the call
is as a member of the object pointed to or referred to."

Your dereferenced foo is not an A object , its an integer.
You code is not standard compliant C++.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Please not the above quote contains the text: "a member of the object".

A little example:

#include <iostream>

struct X
{
static void foo()
{
std::cout << "foo() called" << std::endl;
}
};

int main()
{
X x;
//Postfix exp on static?
(&x)->foo();
return 0;
}

Well, would you say foo() here above is also
a member of the object? It is a member
of all the objects simultaneously (or rather, of
the class), as is the case with non-static
member functions.

By your "postfix expression" argument here above
there is not much difference between static and
non-static member functions.
Your original statement:

-------------------
1) A member function of a class is a static member function.
2) A member function of an object belongs to the instance of
the object it was called on.
-------------------

Why then, by your argument here above, is it possible
to call a postfix expression on it, seeing that postfix
expressions only apply to "members of objects"? And static
members are not "members of objects", but rather of classes (1)
No the C++ standard defines a nonstatic member function can
only be invoked on an Object.

Wrt. point 2, it depends on your definition of "belongs to", as
previously stated.

Kind regards,

Werner
 
P

Paul

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
5.2.2
"The first expression in the postfix expression is then
called the object expression, and the call
is as a member of the object pointed to or referred to."

Your dereferenced foo is not an A object , its an integer.
You code is not standard compliant C++.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Please not the above quote contains the text: "a member of the object".

A little example:

#include <iostream>

struct X
{
static void foo()
{
std::cout << "foo() called" << std::endl;
}
};

int main()
{
X x;
//Postfix exp on static?
(&x)->foo();

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I don't know what the C++ rules are for this syntax.
Is it any different from
x.foo();
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
return 0;
}

Well, would you say foo() here above is also
a member of the object? It is a member
of all the objects simultaneously (or rather, of
the class), as is the case with non-static
member functions.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I don't know , what would you say?
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

By your "postfix expression" argument here above
there is not much difference between static and
non-static member functions.
Your original statement:

-------------------
1) A member function of a class is a static member function.
2) A member function of an object belongs to the instance of
the object it was called on.
-------------------

Why then, by your argument here above, is it possible
to call a postfix expression on it, seeing that postfix
expressions only apply to "members of objects"? And static
members are not "members of objects", but rather of classes (1)
No the C++ standard defines a nonstatic member function can
only be invoked on an Object.

Wrt. point 2, it depends on your definition of "belongs to", as
previously stated.

Kind regards,

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm not into all that standaresque postfix prefix nonsense anyway , all we
need to know for the sake of the discussion is the gwowens code is not
standard compliant code.
And it wasn't even close to solving the recurion problem. :)

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
W

werasm

[snipped]
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I don't know what the C++ rules are for this syntax.
Is it any different from
x.foo();
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  return 0;

}

I specifically used -> instead of . because that
was what we were used in his example. It would
make no difference though.
Well, would you say foo() here above is also
a member of the object? It is a member
of all the objects simultaneously (or rather, of
the class), as is the case with non-static
member functions.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I don't know , what would you say?
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I would say it's a member of the class (being static),
but if we use your quotation of the standard to
disprove what gwowen said, we have to state
that it too is a member of the object (which
contradicts your earlier point if we say that
being a member of an object and class simultaneously
is mutually exclusive):

Your earlier point being:

1) A member function of a class is a static member function.


[snipped, simply because its does not require emphasis]
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm not into all that standaresque postfix prefix nonsense anyway , all we
need to know for the sake of the discussion is the gwowens code is not
standard compliant code.
And it wasn't even close to solving the recurion problem. :)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

You are quick to use it to prove your point though,
even when in proving that point you contradict your
own previous posts.

Kind regards,

Werner
 
G

gwowen

Your dereferenced foo is not an A object ,

Resoloving a non-virtual member function on a POD type is one of the
things you can do without a fully initialised object. Hell, you can
even dereference a pointer to an incomplete type as long as you're
careful with what you do with the result. It's an lvalue, and things
only get undefined when you do an assignment, or rvalue conversion.
See 3.8, 4.1 and 5.3.1 and elsewhere. In my case I can do it because
the storage for z and the storage for foo->num are the same (i.e.
&(foo->num) == &z, same types same address.)
Please not the above quote contains the text: "a member of the object".

Functions members are members? Colour me amazed.
 
P

Paul

[snipped]
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I don't know what the C++ rules are for this syntax.
Is it any different from
x.foo();
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
return 0;

}

I specifically used -> instead of . because that
was what we were used in his example. It would
make no difference though.
Well, would you say foo() here above is also
a member of the object? It is a member
of all the objects simultaneously (or rather, of
the class), as is the case with non-static
member functions.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I don't know , what would you say?
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I would say it's a member of the class (being static),
but if we use your quotation of the standard to
disprove what gwowen said, we have to state
that it too is a member of the object (which
contradicts your earlier point if we say that
being a member of an object and class simultaneously
is mutually exclusive):

Your earlier point being:

1) A member function of a class is a static member function.


[snipped, simply because its does not require emphasis]
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm not into all that standaresque postfix prefix nonsense anyway , all we
need to know for the sake of the discussion is the gwowens code is not
standard compliant code.
And it wasn't even close to solving the recurion problem. :)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

You are quick to use it to prove your point though,
even when in proving that point you contradict your
own previous posts.

zxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Because its true
If you said you have a function that is a member of a class and not a member
of an object anyone would automatically assume you were talking about a
static member.
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top