www.delorie.com/djgpp/bugs/show.cgi   search  
Bug 000349

When Created: 01/12/2002 06:10:14
Against DJGPP version: 2.03
By whom: maprph@bath.ac.uk
Abstract: Constructing member objects on-the-fly inside constructors
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 the 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

}

Here is the DJGPP 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 ()()'

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

I posted this problem on the newsgroup alt.comp.lang.learn.c-c++. A couple of people managed to successfully compile it: one on VC++6.0 and one one MSVC++.

Thanks.

Note added: 01/12/2002 15:38:13
By whom: maprph@bath.ac.uk
I get the same exactly the same problem when I compile through the Cygwin g++ -- obviously then it is something to do with g++ and not djgpp in itself.

Therefore I am posting the problem on gnu.g++

Robert Hardy.

Note added: 01/12/2002 15:45:30
By whom: maprph@bath.ac.uk
...actually, I posted it on gnu.g++.help.

Robert.

Closed on 01/13/2002 06:04:20: Not a DJGPP bug
By whom: eliz@is.elta.co.il



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