Another annoying C++ Problem

Discussion in 'Computer Science & Culture' started by caffeine43, Mar 1, 2002.

Thread Status:
Not open for further replies.
  1. caffeine43 Registered Member

    Messages:
    7
    I have a question about a Linked-List structure...

    I keep getting the error "request for member `AddFirst' in `abc', which is of non-aggregate type `List<int> ()()'"...It is really starting to aggrevate me because no matter what I change, it always is there.... except if I construct the List using a constructor other than the null constructor. All functions are declared in the class definition and the code for them is outside of the class. If anyone can help I would really really appreciate it...

    Thanks a lot!
    -Tom



    Here's my happy little chunk of code that does nothing...

    #include "list.h"

    void main() {
    List<int> abc();
    abc.AddFirst(1);
    }

    And here's the function AddFirst, along with the null constructor...

    template <class T>
    List<T>::List()
    {
    head = tail = 0;
    }

    template <class T>
    void List<T>::AddFirst (const T& a){
    Node *newNode = new Node(a);
    if(IsEmpty())
    head = tail = newNode;
    else
    {
    newNode -> next = head;
    head = newNode;
    }

    }
     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. Bowser Namaste Valued Senior Member

    Messages:
    8,828
    Got me on this one... Might want to try posting it on programmersheaven.com.
     
  4. Google AdSense Guest Advertisement



    to hide all adverts.
  5. caffeine43 Registered Member

    Messages:
    7
    I found the problem...

    When I created the list, I did this...

    List a();

    Then did this to add an element...

    a.AddLast(1);


    Someone in an IRC chat room pointed out that null constructors do not require the (). I removed those and everything worked fine! After doing some research, I found an explanation of the error. The compiler was confused and treated "List a();" as a function, I think...

    So anyway, the "()" cost me like two hours and some hair. Programming is fun...

    Please Register or Log in to view the hidden image!

     
  6. Google AdSense Guest Advertisement



    to hide all adverts.
Thread Status:
Not open for further replies.

Share This Page