hi everyone!i'm working on a project and i'm getting two errors of the type mentioned in the title.
here's the part of the code that generates the problem:

#include "Instance.h"

//default constructor
Instance::Instance(unsigned features) {
	num_of_features = features;
	fileName = "-";
	category = true;

	keywords = new string[num_of_features];
	featureID = new unsigned[num_of_features];
	frequency = new unsigned[num_of_features];
	for (unsigned i = 0; i < num_of_features; i++)
		keywords[i] = "-";
		featureID[i] = 0;
		frequency[i] = 0;

void Instance::setFeature(unsigned i, const string& feature, unsigned featureID, unsigned frequency) {
	keywords[i] = feature;
	featureID[i] = featureID;
	frequency[i] = frequency;

everything's declared in a header file:

class Instance {
	Instance(unsigned features=0);
	Instance(const Instance& original);
	void setFeature(unsigned i, const string& feature, unsigned featureID, unsigned frequency);

	string fileName;
	string* keywords;
	unsigned* featureID;
	unsigned* frequency;
	unsigned num_of_features;
	bool category;

the error appears in line 22 and 23 of the cpp file.
i've already searched similar topics but they didn't turn out to be very helpful..i would really appreciate any help!
thanks in advance

5 Years
Discussion Span
Last Post by paranoidSandra

are you referring to the declarations?
i thought unsigned and unsigned int was the same thing in c++..:S


sure, sorry about that
this is the error:
invalid types 'unsigned int[unsigned int]' for array subscript


It's not a good technic to name function arguments same as class' member variables. In your setFeature function compiler doesn't know if you refer to class' featureID or the argument above. Either rename arguments or specify that you are referring to class' members using this operator: this->featureID in this case.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.