Another annoying C++ Problem

Status
Not open for further replies.

caffeine43

Registered Member
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;
}

}
 
Got me on this one... Might want to try posting it on programmersheaven.com.
 
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... :D
 
Status
Not open for further replies.
Back
Top