Compile error: no appropriate default constructor available

Discussion in 'C++' started by Ook, Oct 29, 2005.

  1. Ook

    Ook Guest

    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(){};
    Ook, Oct 29, 2005
    #1
    1. Advertising

  2. 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
    Valentin Samko, Oct 29, 2005
    #2
    1. Advertising

  3. 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
    Jonathan Mcdougall, Oct 29, 2005
    #3
  4. Ook

    Ook Guest

    "Valentin Samko" <> wrote in message
    news:4363bafc$0$19371$...
    > 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>
    .....
    Ook, Oct 29, 2005
    #4
  5. * "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?
    Alf P. Steinbach, Oct 29, 2005
    #5
  6. 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
    Valentin Samko, Oct 29, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Duy Lam
    Replies:
    4
    Views:
    17,598
    John Harrison
    Jun 12, 2004
  2. Victor Bazarov
    Replies:
    0
    Views:
    506
    Victor Bazarov
    Oct 11, 2004
  3. Richard Herring
    Replies:
    0
    Views:
    5,601
    Richard Herring
    Oct 12, 2004
  4. NoNickName
    Replies:
    4
    Views:
    243
    Jim Langston
    Nov 1, 2005
  5. Replies:
    3
    Views:
    484
    n2xssvv g02gfr12930
    Feb 16, 2006
Loading...

Share This Page