Re: What's wrong withthe code?
From: Kevin Goodsell (usenet2.spamfree.fusion_at_neverbox.com)
Date: 04/19/04
- Next message: Paul Mensonides: "Re: Index a #define string"
- Previous message: Benoit Mathieu: "Re: Is this legal?"
- In reply to: Rob Williscroft: "Re: What's wrong withthe code?"
- Next in thread: Rob Williscroft: "Re: What's wrong withthe code?"
- Reply: Rob Williscroft: "Re: What's wrong withthe code?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 18 Apr 2004 22:26:42 GMT
Rob Williscroft wrote:
> Kevin Goodsell wrote in news:S2Agc.19892$A_4.3903
> @newsread1.news.pas.earthlink.net in comp.lang.c++:
>
>>
>>Can you really have a static member that is the same type as the class
>>it is a member of? What would that even mean? Would you have infinitely
>>nested 'membs' that are really all the same object?
>>
>
>
> static members are members of the class (of which there is only one).
>
> So the static instance's class has a member which is the instance
> itself, recursion would be if the instance *contained* itself, which
> it doesn't.
>
> Similar perhaps to an object that contains a /pointer/ to itself.
>
> Rob.
So the following is legal, if I understand correctly:
#include <iostream>
struct Test
{
static Test t;
};
Test Test::t;
int main()
{
Test a;
if (&(a.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t) == &(a.t))
{
std::cout << "Hmmmm..." << std::endl;
}
return 0;
}
g++ (-W -Wall -ansi -pedantic) accepts this and prints "Hmmmm...". It
shows what I meant by "infinitely nested [objects] that are really all
the same object". It makes sense (sort of), but seems strange to me.
-Kevin
-- My email address is valid, but changes periodically. To contact me please use the address from a recent posting.
- Next message: Paul Mensonides: "Re: Index a #define string"
- Previous message: Benoit Mathieu: "Re: Is this legal?"
- In reply to: Rob Williscroft: "Re: What's wrong withthe code?"
- Next in thread: Rob Williscroft: "Re: What's wrong withthe code?"
- Reply: Rob Williscroft: "Re: What's wrong withthe code?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|