Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #8561 > unrolled thread
| Started by | balaji <kasthurirangan.balaji@gmail.com> |
|---|---|
| First post | 2011-08-08 02:00 -0700 |
| Last post | 2011-08-10 12:06 +0000 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.c++
help on constructor/constructor initialization list with inheritance using templates balaji <kasthurirangan.balaji@gmail.com> - 2011-08-08 02:00 -0700
Re: help on constructor/constructor initialization list with inheritance using templates jt@toerring.de (Jens Thoms Toerring) - 2011-08-08 09:46 +0000
Re: help on constructor/constructor initialization list with inheritance using templates balaji <kasthurirangan.balaji@gmail.com> - 2011-08-10 04:01 -0700
Re: help on constructor/constructor initialization list with inheritance using templates jt@toerring.de (Jens Thoms Toerring) - 2011-08-10 12:06 +0000
| From | balaji <kasthurirangan.balaji@gmail.com> |
|---|---|
| Date | 2011-08-08 02:00 -0700 |
| Subject | help on constructor/constructor initialization list with inheritance using templates |
| Message-ID | <9086d735-ed4d-4943-9d01-40f3d0f726b5@l11g2000prh.googlegroups.com> |
Hi,
Pls find below the sample code.
File 1
template< class A, template < typename > class B >
class C : public B<A>
{
public:
explicit C(const char *msg);
~C();
private:
//copy constructor and assignment operator
}
template< class A, template < typename > class B >
C<A, B> :: C(const char *msg)
: B(msg)
{
}
template< class A, template < typename > class B >
C<A, B> :: ~C()
{
}
File 2
template < class Z>
class B : public Z
{
public:
explicit B(const char *msg);
~B();
private:
//copy constructor and assignment operator
}
template < class Z>
B<Z> :: B(const char *msg)
: Z(msg)
{
}
template < class Z>
B<Z>::~B()
{
}
File 3
3.h
class A
{
public:
explicit A(const char *msg);
~A();
private:
//copy constructor and assignment operator
}
3.C
#include "3.h"
A::A(const char *msg)
{
}
A::~A()
{
}
main file
#iinclude file 1, file 2 and file 3(.h)
int
main(int argc, char **argv)
{
C<A,B> objc("Success");
return 0;
}
when i compile this code, i get the following error "The base class
"B<A>" cannot be initialized because it does not have a default
constructor.". I do not understand what i have missed to get this
error. Pls help me to resolve this.
Thanks,
Balaji.
[toc] | [next] | [standalone]
| From | jt@toerring.de (Jens Thoms Toerring) |
|---|---|
| Date | 2011-08-08 09:46 +0000 |
| Message-ID | <9a9pkfFft8U1@mid.uni-berlin.de> |
| In reply to | #8561 |
balaji <kasthurirangan.balaji@gmail.com> wrote:
> Hi,
> Pls find below the sample code.
> File 1
> template< class A, template < typename > class B >
> class C : public B<A>
> {
> public:
> explicit C(const char *msg);
> ~C();
> private:
> //copy constructor and assignment operator
> }
You're missing a semicolon here (and also is some other
places at the end of declarations of classes).
> template< class A, template < typename > class B >
> C<A, B> :: C(const char *msg)
> : B(msg)
This is the place my compiler doesn't like when other,
minor issues are fixed:
error: no matching function for call to ‘B<A>::B()’
note: candidates are: B<Z>::B(const char*) [with Z = A]
note: B<A>::B(const B<A>&)
Shouldn't that be
template< class A, template < typename > class B >
C< A, B > :: C( const char * msg )
: B< A >( msg )
since B<A> is the base class C is derived from?
Otherwise I guess the compiler will try to invoke the
default constructor of B<A> (since there's no explicit
call of it - you call B(msg), not B<A>(msg)) and since
there is none it gives up.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
[toc] | [prev] | [next] | [standalone]
| From | balaji <kasthurirangan.balaji@gmail.com> |
|---|---|
| Date | 2011-08-10 04:01 -0700 |
| Message-ID | <e1d432de-eb4a-4c28-9fff-477c417281bd@a2g2000prf.googlegroups.com> |
| In reply to | #8562 |
On Aug 8, 2:46 pm, j...@toerring.de (Jens Thoms Toerring) wrote:
> balaji <kasthurirangan.bal...@gmail.com> wrote:
> > Hi,
> > Pls find below the sample code.
> > File 1
> > template< class A, template < typename > class B >
> > class C : public B<A>
> > {
> > public:
> > explicit C(const char *msg);
> > ~C();
> > private:
> > //copy constructor and assignment operator
> > }
>
> You're missing a semicolon here (and also is some other
> places at the end of declarations of classes).
>
> > template< class A, template < typename > class B >
> > C<A, B> :: C(const char *msg)
> > : B(msg)
>
> This is the place my compiler doesn't like when other,
> minor issues are fixed:
>
> error: no matching function for call to ‘B<A>::B()’
> note: candidates are: B<Z>::B(const char*) [with Z = A]
> note: B<A>::B(const B<A>&)
>
> Shouldn't that be
>
> template< class A, template < typename > class B >
> C< A, B > :: C( const char * msg )
> : B< A >( msg )
>
> since B<A> is the base class C is derived from?
>
> Otherwise I guess the compiler will try to invoke the
> default constructor of B<A> (since there's no explicit
> call of it - you call B(msg), not B<A>(msg)) and since
> there is none it gives up.
> Regards, Jens
> --
> \ Jens Thoms Toerring ___ j...@toerring.de
> \__________________________ http://toerring.de
Hi Jens,
Thanks for your response and sorry for the late reply as well.
My post wasn't posted atleast for 2 days i believe or atleast i was
unable to see this post.
I too figured out that. What compiler is yours to give the
"candidates". My compiler didn't say that(itx IBM xlC version 7.0).
Thanks,
Balaji.
[toc] | [prev] | [next] | [standalone]
| From | jt@toerring.de (Jens Thoms Toerring) |
|---|---|
| Date | 2011-08-10 12:06 +0000 |
| Message-ID | <9afai7Fm36U1@mid.uni-berlin.de> |
| In reply to | #8616 |
balaji <kasthurirangan.balaji@gmail.com> wrote:
> On Aug 8, 2:46 pm, j...@toerring.de (Jens Thoms Toerring) wrote:
> > balaji <kasthurirangan.bal...@gmail.com> wrote:
> > > template< class A, template < typename > class B >
> > > C<A, B> :: C(const char *msg)
> > > : B(msg)
> >
> > This is the place my compiler doesn't like when other,
> > minor issues are fixed:
> >
> > error: no matching function for call to ‘B<A>::B()’
> > note: candidates are: B<Z>::B(const char*) [with Z = A]
> > note: B<A>::B(const B<A>&)
> >
> > Shouldn't that be
> >
> > template< class A, template < typename > class B >
> > C< A, B > :: C( const char * msg )
> > : B< A >( msg )
>
> I too figured out that. What compiler is yours to give the
> "candidates". My compiler didn't say that(itx IBM xlC version 7.0).
It's gcc, version 4.4.3. Having the candidates the compiler
considered being shown can be helpful but also, at other times,
a bit annoying when the compiler found hundreds and hundreds
of them and insists on listing each and every one of them;-)
Best regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web