Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > About incomplete class definition

Reply
Thread Tools

About incomplete class definition

 
 
CC Jia
Guest
Posts: n/a
 
      10-30-2010
Hi, guys, I'm a cpp newbie.
I have a question about class definition, here is:
class C{
public:
C test2(){std::cout<<"test2\n"; return *this;}
void print();
C testDefinition();
};

As i know, in class definition, it is incomplete, why can I make
return a object of this class?
 
Reply With Quote
 
 
 
 
CC Jia
Guest
Posts: n/a
 
      10-30-2010
On 10月30日, 下午11时18分, Paavo Helde <(E-Mail Removed)> wrote:
> CC Jia <(E-Mail Removed)> wrote in news:61ae2f5e-92e9-46cc-be4e-
> (E-Mail Removed):
>
> > Hi, guys, I'm a cpp newbie.
> > I have a question about class definition, here is:
> > class C{
> > public:
> > C test2(){std::cout<<"test2\n"; return *this;}
> > void print();
> > C testDefinition();
> > };

>
> > As i know, in class definition, it is incomplete, why can I make
> > return a object of this class?

>
> For testDefinition(), this is only a declaration, which is OK with
> incomplete types.
>
> For test2(): from C++ standard 9.2/2: "Within the class member-
> specification, the class is regarded as complete within function bodies,
> [...]"
>
> It seems the aim has been that when defining member functions inside the
> class definition one should not encounter strange restrictions, the
> compiler is required to handle them in the same way as if they were
> defined outside of the class definition (and marked "inline" explicitly).
>
> hth
> Paavo


yes, thank you, your reply is clear, i can understand
 
Reply With Quote
 
 
 
 
Johannes Schaub (litb)
Guest
Posts: n/a
 
      10-30-2010
CC Jia wrote:

> Hi, guys, I'm a cpp newbie.
> I have a question about class definition, here is:
> class C{
> public:
> C test2(){std::cout<<"test2\n"; return *this;}
> void print();
> C testDefinition();
> };
>
> As i know, in class definition, it is incomplete, why can I make
> return a object of this class?


For test2, it's helpful to consult the exact rule: "The type of a parameter
or the return type for a function definition shall not be an incomplete
class type (possibly cv-qualified) unless the function definition is nested
within the member-specification for that class (including definitions in
nested classes defined within the class)."

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Decralation of class inside other class and definition outside this class =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki C++ 2 07-12-2007 11:52 PM
Automagic determination of definition based on definition location. Jon Slaughter C++ 4 10-26-2005 05:00 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
can a class definition inside another class's definition Jianli Shen C++ 1 03-13-2005 06:02 PM
help?: incomplete definition with complete definition in scope Ark C Programming 1 08-07-2004 04:21 PM



Advertisments