delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/01/11/06:30:19

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
From: "Robert Hardy" <maprph AT bath DOT ac DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: BUG? : Constructing member objects on-the-fly inside constructors.
Date: Fri, 11 Jan 2002 10:36:57 +0000 (UTC)
Organization: BT Openworld
Lines: 71
Message-ID: <a1mf88$4b3$1@knossos.btinternet.com>
NNTP-Posting-Host: host213-122-35-39.btinternet.com
X-Trace: knossos.btinternet.com 1010745417 4451 213.122.35.39 (11 Jan 2002 10:36:57 GMT)
X-Complaints-To: usenet AT knossos DOT btinternet DOT com
NNTP-Posting-Date: Fri, 11 Jan 2002 10:36:57 +0000 (UTC)
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MSMail-Priority: Normal
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I have a class contains_int that contains only an integer value.
I have a class contains_contains_int that contains only an object of class
contains_int.


Here is my code:

#include<iostream>

class contains_int {
      int i;
      public:
             contains_int(int ii): i(ii) {}
             void printme() {cout << "( int: " << i << " )"; }
             int getme() {return i;}
};

class contains_contains_int {
      contains_int c_i;
      public:
             contains_contains_int(contains_int c_ii): c_i(c_ii) {}
             void printme() {cout << "( c_i : ";
                  c_i.printme(); cout << " )"; }
};

class contains_contains_contains_int {
      contains_contains_int cc_i;
      public:
             contains_contains_contains_int(contains_contains_int cc_ii) :
             cc_i(cc_ii) {}
             void printme() {cout << "( cc_i : ";
                  cc_i.printme(); cout << " )"; }
};

int main() {
    int a=7;
    contains_int b(a);
    contains_contains_int c(b);
    contains_contains_contains_int d(c);
    cout << " a = ( " << a << " )" << endl;
    cout << " b = "; b.printme(); cout << endl;
    cout << " c = "; c.printme(); cout << endl;
    cout << " d = "; d.printme(); cout << endl;

    contains_contains_contains_int x( contains_contains_int (
contains_int(10) ));
    cout << " x = "; x.printme(); cout << endl;         //line A

}

My issue is that I would like to create objects like x -- constructing its
member objects on-the-fly as it were --
rather than having to build them up line-by-line as I do with the series a,
b, c and d.


DJGPP gives me the following error message:

In function `int main()':
Error (line A): request for member `printme' in `x', which is of
non-aggregate type `contains_contains_contains_int ()()'

I originally posted this query in alt.comp.lang.learn.c++ (it should still
be there if you want to see the replies) and other people in the group tried
the code on their compilers and it worked okay.
Perhaps this is a problem with DJGPP?

Thanks, Robert.



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019