octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: default constructor and class


From: Marco Vassallo
Subject: RE: default constructor and class
Date: Mon, 8 Jul 2013 21:47:06 +0200

________________________________
> Date: Mon, 8 Jul 2013 15:42:41 -0400 
> Subject: Re: default constructor and class 
> From: address@hidden 
> To: address@hidden 
> CC: address@hidden 
>  
>  
> On Mon, Jul 8, 2013 at 3:34 PM, Marco Vassallo  
> <address@hidden<mailto:address@hidden>> wrote: 
> ________________________________ 
> > Date: Mon, 8 Jul 2013 15:27:45 -0400 
> > Subject: Re: default constructor and class 
> > From: address@hidden<mailto:address@hidden> 
> > To: address@hidden<mailto:address@hidden> 
> > CC: address@hidden<mailto:address@hidden> 
> > 
> > On Mon, Jul 8, 2013 at 3:20 PM, Marco Vassallo 
> >  
> <address@hidden<mailto:address@hidden><mailto:address@hidden<mailto:address@hidden>>>
>   
> wrote: 
> > Hi all, 
> > 
> > for the fem-fenics pkg I'm creating a new class, and I thus add as 
> > private members 
> > 
> >    DECLARE_OCTAVE_ALLOCATOR; 
> >    DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA; 
> > 
> > and also the DEFINE counterpart, 
> > 
> > which requires the class to have a default constructor (right?) 
> > 
> > The problem is that one of the parent class from which I derive my  
> own class 
> > doesn't provide a default constructor. Example 
> > 
> > class B: public octave_base_value, public A 
> > { 
> >    B(): octave_base_value(), A(), B() {} //error: A() not available 
> > 
> >    private: 
> >    A my_element; 
> >    DECLARE_OCTAVE_ALLOCATOR; 
> >    DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA; 
> > } 
> > 
> > How can I manage it? 
> > 
> > I'm not sure I understand your construct correctly, but is it 
> > intentional that B inherits from A *and* contains a A object 
> > (my_element)? Can't you get rid of the inheritance from A and just have 
> > the my_element member? 
> > 
> > Michael. 
>  
> This class should be a wrapper for the A class. 
> Even if I avoid deriving from A, 
>  
>   class B: public octave_base_value 
> { 
>   B(): octave_base_value() {} //error: default constructor for  
> my_element not available 
>  
>   private: 
>   A my_element; 
>   DECLARE_OCTAVE_ALLOCATOR; 
>   DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA; 
>   } 
>  
> I still need a constructor for my_elements, and as it is an object of  
> type A I 
> need to initialize it somehow. 
>  
> Why don't you do the following instead for the default constructor of  
> class B: 
>  
> B(): octave_base_value(), my_element(<whatever_argument>) {} 
>
This is exactly what I'm doing, but the <whatever_argument> is something which
I added to the class only for this purpose and which should not be there.
In my class there should be nothing else then 

A my_element;

Marco 
> Michael. 
>                                         

reply via email to

[Prev in Thread] Current Thread [Next in Thread]