I don't know what i'm missing, but I keep getting the error in the poly_tst file when trying to compile that says 'expected primary-expression before ']' token. According to my book I'm writing everything correctly.


Here is my class file function (poly.h)

void setcoeff(Term);

Here is my implementation file definition (poly.cpp)

void poly::setcoeff(Term Termholder[])

Here is my driver file function call (poly_tst.cpp)

polyinstance.setcoeff(Termholder[]);

Other notes is that I have a structure called Term that I created in the class that I made an array of 10 elements of called Termholder, and that my declared instance of a poly is called polyinstance

Recommended Answers

All 2 Replies

polyinstance.setcoeff(Termholder[]); -- you don't need []. Also void setcoeff(Term)!=void poly::setcoeff(Term Termholder[]), first declares function taking one Term argument, and the second defines function taking array of Term argument.

Zjarek is correct.
And the error message is related to the fact that the use of [] without anything inside of it is only permitted in a few cases (when declaring a parameter to a function or when declaring a static array whose size is determined by its initializer), in all other cases, the compiler expects you to put something in-between (i.e. an index) and when it does not find it, it throws an error "expected primary-expression".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.