0

i have the following struct defined:

typedef struct PList{
    Person person;
    struct PList *nextPerson;  //  set to NULL by default <<<<<
}PList;

and this method:

int length(struct PList* db){
    PList* cur = db;
    int size = 0;
    while (cur != NULL){
    ++size;
    cur = cur->nextPerson;
}
    return size;
}

error: conflicting types for 'length' is being thrown at the signature for the length method.

Any ideas?

2
  • 3
    You have a conflicting declaration or definition of length elsewhere in your code. Commented Nov 28, 2012 at 16:33
  • You have a function definition that does not match the function declaration signature Commented Nov 28, 2012 at 16:34

1 Answer 1

2

That actually means that there is another function/declaration called length elsewhere in your source code structure that has a different function signature.

Find where length() function is defined, and pass correct structure objects to that function(either of type struct PList or PList*)

Sign up to request clarification or add additional context in comments.

5 Comments

So you cannot have 3 methods that take as parameters different structs? Overloading it kindof..
No - not in C - you can in C++ though.
You cannot do function overloading in C. Its possible in C++ however
In C++, while you can technically overload a global function (such as length) for different class types, one would generally make length a method of the class. So foo.length() is more idiomatic than length(foo)...*most* of the time.
yes but i don't think it's possible to do anything of the sort since C isn't Object Oriented. I also don't think it's actually possible to implement it using something like a general struct since i don't think anything like inheritance is implemented for structs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.