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

Recommended Answers

All 7 Replies

What about using unsigned int ?

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

Could you please post the errors as they appear?

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.

featureID[i] = featureID; Naming conflict?

you're right, i changed it to this->featureID and it works fine!thanks a lot!

Be a part of the DaniWeb community

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