220 4082 <CAGqM8fbzQuTd+udZRrrUoGLXtgm+RuP8pSYPv=bBDpxMxSNmMA@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Lawrence Crowl <crowl@googlers.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: A cleaner way to define nested class/structure
Date: Mon, 29 Apr 2013 11:57:53 -0700
Lines: 79
Approved: news@gmane.org
Message-ID: <CAGqM8fbzQuTd+udZRrrUoGLXtgm+RuP8pSYPv=bBDpxMxSNmMA@mail.gmail.com>
References: <27175469-a158-4bc1-9f30-66e3a647e931@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
X-Trace: ger.gmane.org 1367261877 12802 80.91.229.3 (29 Apr 2013 18:57:57 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 29 Apr 2013 18:57:57 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCY3D77DYUDBBM4F7OFQKGQEXGXAIPA@isocpp.org Mon Apr 29 20:57:58 2013
Return-path: <std-proposals+bncBCY3D77DYUDBBM4F7OFQKGQEXGXAIPA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-oa0-f69.google.com ([209.85.219.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCY3D77DYUDBBM4F7OFQKGQEXGXAIPA@isocpp.org>)
	id 1UWtGv-0002qV-Gq
	for gclcip-std-proposals@m.gmane.org; Mon, 29 Apr 2013 20:57:57 +0200
Original-Received: by mail-oa0-f69.google.com with SMTP id l20sf41367649oag.4
        for <gclcip-std-proposals@m.gmane.org>; Mon, 29 Apr 2013 11:57:56 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=googlers.com; s=googlers;
        h=x-received:x-beenthere:x-received:received-spf:mime-version
         :x-received:in-reply-to:references:date:message-id:subject:from:to
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:x-google-group-id:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe:content-type;
        bh=yEdxAilQITyO9uPLMCbAlYQ4FMFVCfwyNzoNQRi//0w=;
        b=C11aLjCVna0XpO9nkV38FsfA1XEVcFj5/XHUNO/eDtWLtXw6ubwTeHcqD68poJHT72
         XUuwVNJTqmw7AXjx4IniXUhPpXK6kh+ZxDoXyQvRWodjaIhTob7QQXkkPnF9VtyA3TxG
         7smIpU5lz29KztTEhGmWVXZ/4dVw6RW6bb0KA=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20120113;
        h=x-received:x-beenthere:x-received:received-spf:mime-version
         :x-received:in-reply-to:references:date:message-id:subject:from:to
         :x-gm-message-state:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-google-group-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=yEdxAilQITyO9uPLMCbAlYQ4FMFVCfwyNzoNQRi//0w=;
        b=hsOUFvQykULfvkAm3TjeJy8QcGMFi+YDKuGIO2pCAIHEvybkCIulNLamyYJcNCABR+
         wkFz39udiAonW39fz51z6PN3aZ0P5+HcSO+BEK6529w5jryAkqo4SPYLaZd91XZKGHKE
         fCkhH+6bUgH0WYEN61/3noU1u89QYHmMCq2WbDhYcQ9/7AhgvkdIUyE01+qu1DBpHfan
         Bujw4zmDFbquLeVExKFCHxLDyRNnPdEpDyvvjVA+wxDrsEf53IGNQuWfzHH3/oYD1jj2
         qrqoRkclEh8vbABiZ8JclHCRDSH7x1o 
X-Received: by 10.43.113.131 with SMTP id ew3mr42353052icc.24.1367261876258;
        Mon, 29 Apr 2013 11:57:56 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.154.102 with SMTP id vn6ls430072igb.23.canary; Mon, 29 Apr
 2013 11:57:54 -0700 (PDT)
X-Received: by 10.42.95.195 with SMTP id g3mr29421118icn.14.1367261874211;
        Mon, 29 Apr 2013 11:57:54 -0700 (PDT)
Original-Received: from mail-ie0-x22e.google.com (mail-ie0-x22e.google.com [2607:f8b0:4001:c03::22e])
        by mx.google.com with ESMTPS id dd9si12541602igc.7.2013.04.29.11.57.54
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Mon, 29 Apr 2013 11:57:54 -0700 (PDT)
Received-SPF: pass (google.com: domain of crowl@google.com designates 2607:f8b0:4001:c03::22e as permitted sender) client-ip=2607:f8b0:4001:c03::22e;
Original-Received: by mail-ie0-f174.google.com with SMTP id 10so7647516ied.5
        for <std-proposals@isocpp.org>; Mon, 29 Apr 2013 11:57:54 -0700 (PDT)
X-Received: by 10.50.171.73 with SMTP id as9mr1700397igc.23.1367261873997;
 Mon, 29 Apr 2013 11:57:53 -0700 (PDT)
Original-Received: by 10.231.110.80 with HTTP; Mon, 29 Apr 2013 11:57:53 -0700 (PDT)
In-Reply-To: <27175469-a158-4bc1-9f30-66e3a647e931@isocpp.org>
X-Gm-Message-State: ALoCoQnlO/PaS2UGdJ/poebw1kKoUCLv3K5kwYMwAAT4cNegbyRh143Q4YBJNq//3zQwQIH2XhOv0l0ddzwv9rsi6Ya2bxyQ+J/ovEyEdys35n+1+fN8UcpUoa1o2VGfjwAvanRNgx0dtuH+Ek/21X8C+dphBdTTgfUbnSz6M8nIiPwgM9IyiBXyUCvRO4l0CMzjFib35KTY
X-Original-Sender: crowl@googlers.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of crowl@google.com designates 2607:f8b0:4001:c03::22e as permitted
 sender) smtp.mail=crowl@google.com;       dkim=pass header.i=@googlers.com;
       dmarc=pass (p=NONE dis=none) d=googlers.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post?hl=en>,
 <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?hl=en&topic=25838>,
 <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:4082
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/4082>

On 4/29/13, Hariharan Subramanian <tohari@gmail.com> wrote:
> Problem:
>
> class Outer {
> class Inner1;
> class Inner2;
>
> Inner1 inner1;
> Inner2 *inner2;
> };
>
> class Outer::Inner1 {
> int i1;
> };
>
> class Outer::Inner2 {
> int i2;
> };
>
> The code above results in compilation error because the class Inner1 is not
>
> defined before the declaration of the object inner1. Inner2 obviously has
> no problem.Defining the nested classes within the Outer class hampers
> readability.
>
> Solution:
>
> class Outer; //Declare the Outer class
>
> class Outer::Inner1 { //Define the Inner1 class
> int i1;
> };
>
> class Outer {           //If this class is not defined in the same
> compilation unit then it should result in an error because Inner1 is
> defined as a nested class but the nesting class is undefined.
> class Inner1;   //If this is absent then it should result in compilation
> error
> class Inner2;
>
> Inner1 inner1;
> Inner2 *inner2;
> };
>
> class Outer::Inner2 {
> int i2;
> };
>
> This solution honours the C++ convention that the class must be defined
> before creating an object of its type. This certainly improves readability.

Why isn't the following solution sufficient?

class Outer {
  class Inner1 {
    int i1;
  };
  class Inner2;
  Inner1 inner1;
  Inner2 *inner2;
};

class Outer::Inner2 {
  int i2;
};

-- 
Lawrence Crowl

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.



.
