Compile error: no appropriate default constructor available

O

Ook

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(){};
 
V

Valentin Samko

Ook said:
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> .
 
J

Jonathan Mcdougall

Ook said:
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
 
O

Ook

Valentin Samko said:
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>
.....
 
A

Alf P. Steinbach

* "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...
 
V

Valentin Samko

Ook said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top