Thread: Template and Inheritance

  1. #1
    Unregistered
    Guest

    Template and Inheritance

    Hi everyone
    I have major problems with my code and need help with the way I am writing my template inheritance class for LinkList (base class) and Stack (inheriting LinkList) and Queue(inheriting LinkList) I am getting a complier error in both Stack class and Queue class that I don't what it means
    What does this error mean ?
    " ambiguous call to overloaded function while compiling class-template member function"
    This error is on the constructor of the Queue class (same error for Stack too )

    Any one has references for template inheritance ? I am lost in the syntax codes.

    -thanks

  2. #2
    Davros
    Guest
    Somewhere your compiler can't resolve which function to call. This will happen if you have two methods like this:

    int func(int a, int b = 0);
    int func(int c);

    if you where to call func(5) for example, you will get this error.

  3. #3
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    c++ has complicated rules for resolving overloaded functions
    such as

    void f(int n);
    void f(double n);

    f(4);
    f(4f);

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >This error is on the constructor of the Queue class (same error for Stack too )
    Could you post some code? It's just a tad easier to find the problem when we have source to look at.

    -Prelude
    My best code is written with the delete key.

  5. #5
    Unregistered
    Guest
    here is the code:::

    class List
    {
    protected:
    struct LinkListElement{
    int key;
    int payLoad;
    LinkListElement *p;
    };
    int length;
    LinkListElement *head;

    public:
    //Constructor
    List(int size = 20)
    {
    head = new LinkListElement;
    length = size > 0 ? size: 20;
    head->key = 0;
    head-> payLoad = NULL;
    head->next;
    }
    //Destructor
    ~List();
    // some other pop and push stuff

    ----------- Definition for Stack----------
    class Stack : private List
    {
    private:
    int top;

    public:
    Stack() { } // apparantly this is a problem, because when i try to
    // instantiate the object of class Stack, I get errors

    ~Stack();
    // some other junk here
    };

    -thanks alog

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 04-15-2009, 02:47 PM
  2. Inheritance + Template
    By audinue in forum C++ Programming
    Replies: 5
    Last Post: 07-20-2008, 12:51 AM
  3. Need Help Please
    By YouShallNotPass in forum C++ Programming
    Replies: 3
    Last Post: 08-22-2006, 11:22 AM
  4. Questions about Templates
    By Shamino in forum C++ Programming
    Replies: 4
    Last Post: 12-18-2005, 12:22 AM