Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Compile error: no appropriate default constructor available

Reply
Thread Tools

Compile error: no appropriate default constructor available

 
 
Ook
Guest
Posts: n/a
 
      10-29-2005
Here is my code, can some kind soul tell me what I'm doing wrong, or why I
get this compile error, and maybe what to do to prevent it? I think I must
be missing some fundamental concept here, or maybe the syntax is just not
quite right?

template <typename T>
class DList
{
public:
DList(){};
};
class Polynomial2 : public DList
{
public:
Polynomial2(){};
};
int main()
{
return 0;
}

I'm getting compile error:

'DList' : no appropriate default constructor available

at

Polynomial2(){};


 
Reply With Quote
 
 
 
 
Valentin Samko
Guest
Posts: n/a
 
      10-29-2005
Ook wrote:
> Here is my code, can some kind soul tell me what I'm doing wrong, or why I
> get this compile error, and maybe what to do to prevent it? I think I must
> be missing some fundamental concept here, or maybe the syntax is just not
> quite right?
>
> template <typename T>
> class DList
> {
> public:
> DList(){};
> };
> class Polynomial2 : public DList
> {
> public:
> Polynomial2(){};
> };
> int main()
> {
> return 0;
> }


DList is a template class, i.e. it requires a template parameter.
Your class Polynomial2 inherits from DList, and you did not specify the template parameter
for DList. For example, you could have
class Polynomial2 : public DList<int> .

--

Valentin Samko - http://www.valentinsamko.com
 
Reply With Quote
 
 
 
 
Jonathan Mcdougall
Guest
Posts: n/a
 
      10-29-2005
Ook wrote:
> Here is my code, can some kind soul tell me what I'm doing wrong, or why I
> get this compile error, and maybe what to do to prevent it? I think I must
> be missing some fundamental concept here, or maybe the syntax is just not
> quite right?
>
> template <typename T>
> class DList
> {
> public:
> DList(){};
> };
> class Polynomial2 : public DList


class DList does *not* exist. A family of classes bearing the name
DList exists and to get one of these classes, you must specify its
template parameters:

class P : public DList<int>

What do you think templates are for? This is such a simple example, and
yet you don't understand it. Either this is too advanced for you, or
your textbook (you do have one, don't you?) is scrap.

> {
> public:
> Polynomial2(){};
> };
> int main()
> {
> return 0;
> }
>
> I'm getting compile error:
>
> 'DList' : no appropriate default constructor available


That's a poorly diagnosed message. What this means is that the template
DList must have an argument list.


Jonathan

 
Reply With Quote
 
Ook
Guest
Posts: n/a
 
      10-29-2005

"Valentin Samko" <(E-Mail Removed)> wrote in message
news:4363bafc$0$19371$(E-Mail Removed) eenews.net...
> Ook wrote:
>> Here is my code, can some kind soul tell me what I'm doing wrong, or why
>> I get this compile error, and maybe what to do to prevent it? I think I
>> must be missing some fundamental concept here, or maybe the syntax is
>> just not quite right?
>>
>> template <typename T>
>> class DList
>> {
>> public:
>> DList(){};
>> };
>> class Polynomial2 : public DList
>> {
>> public:
>> Polynomial2(){};
>> };
>> int main()
>> {
>> return 0;
>> }

>
> DList is a template class, i.e. it requires a template parameter.
> Your class Polynomial2 inherits from DList, and you did not specify the
> template parameter for DList. For example, you could have
> class Polynomial2 : public DList<int> .
>
> --
>
> Valentin Samko - http://www.valentinsamko.com


Holy moly, 60 seconds and there is an answer here!!! Yes, that is what I was
missing - so, let me make sure I understand. Since Polynomial2 inherits from
DList, then I specify the type of item DList takes, or I make Polynomial2
also a template class so I can do this.

template <typename T>
class DList
{
public:
DList(){};
};
template <typename T>
class Polynomial2 : public DList<T>
.....


 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      10-29-2005
* "Ook" <Ook Don't send me any freakin' spam at zootal dot com delete
the Don't send me any freakin' spam>:
> Here is my code, can some kind soul tell me what I'm doing wrong, or why I
> get this compile error, and maybe what to do to prevent it? I think I must
> be missing some fundamental concept here, or maybe the syntax is just not
> quite right?
>
> template <typename T>
> class DList
> {
> public:
> DList(){};
> };
> class Polynomial2 : public DList
> {
> public:
> Polynomial2(){};
> };
> int main()
> {
> return 0;
> }
>
> I'm getting compile error:
>
> 'DList' : no appropriate default constructor available
>
> at
>
> Polynomial2(){};


The reason is that you don't use indentation and whitespace in general.

Combined with a compiler that gives you a very misleading error.

The syntax is absolutely not quite right: note that DList is a template
class, then check your usage...

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
Reply With Quote
 
Valentin Samko
Guest
Posts: n/a
 
      10-29-2005
Ook wrote:
>> DList is a template class, i.e. it requires a template parameter.
>> Your class Polynomial2 inherits from DList, and you did not specify the
>> template parameter for DList. For example, you could have
>> class Polynomial2 : public DList<int> .

>
> Holy moly, 60 seconds and there is an answer here!!! Yes, that is what I was
> missing - so, let me make sure I understand. Since Polynomial2 inherits from
> DList, then I specify the type of item DList takes, or I make Polynomial2
> also a template class so I can do this.
>
> template <typename T>
> class DList
> {
> public:
> DList(){};
> };
> template <typename T>
> class Polynomial2 : public DList<T>


Yes, in both cases you specify the type.

--

Valentin Samko - http://www.valentinsamko.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A constructor calling another constructor (default constructor)? Generic Usenet Account C++ 10 11-28-2007 04:12 AM
no appropriate default constructor available denis_browne@hotmail.com C++ 3 02-16-2006 10:12 AM
Re: no appropriate default constructor available?? Richard Herring C++ 0 10-12-2004 12:37 PM
Re: no appropriate default constructor available?? Victor Bazarov C++ 0 10-11-2004 08:47 PM
no appropriate default constructor Duy Lam C++ 4 06-12-2004 08:27 AM



Advertisments