I've been banging my head on this errors and can't seem to find where I went wrong. For any of the "set_" errors, set_ (as well as print) refers to a member function of another class . Please, any help would be great.

test.cpp: In member function `void CDCollection::get(int, std::ofstream&)':
error: `print' is not a type
error: request for member of non-aggregate type before '(' token

test.cpp: In member function `void CDCollection::add(std::istream&)':
error: `set_artist' has not been declared

error: request for member of non-aggregate type before '(' token
error: `set_title' has not been declared
error: request for member of non-aggregate type before '(' token

error: `set_year' has not been declared
error: request for member of non-aggregate type before '(' token
error: `set_descrip' has not been declared
error: request for member of non-aggregate type before '(' token

Execution terminated

class:

class CDCollection
{
	public:
        CDCollection();
        void print(ofstream &output);
		void get(int num_cds, ofstream &out);
		void add(istream& in);
	
	
	
	private:
		int num_cds, cdTotal, max;
		char cdArray[100];
};

CDCollection::CDCollection()
{
	cdTotal = 0;
}

void CDCollection::get(int num_cds, ofstream &out)
{
	cdArray[num_cds].print(out);
}
void CDCollection::print(ofstream &out)
{
	out << "CD COLLECTION:" << endl;
	for (int num_cds = 0; num_cds < cdTotal; num_cds++)
	{	
		get(num_cds, out);
	}
}
void CDCollection::add(istream& in)
{
	max = 100;
	if (cdTotal < max)
	{
		SString artist;
		SString title;
		SString descrip;
		SString test;
		int year;
		char plus[10];
		
		in >> artist;
		in >> title;
		in >> year;
		in.getline(plus,10);
		in >> test;
		
		while(1)
		{
			
			if (test.str_compare("END\n") == 0)	
			{	
				break;
			}
			
			SString new_line("\n",1);
			descrip + test;
			descrip + new_line;
			in >> test;
		}
		
		cdArray[cdTotal].set_artist(artist);
		cdArray[cdTotal].set_title(title);
		cdArray[cdTotal].set_year(year);
		cdArray[cdTotal].set_descrip(descrip);
		cdTotal = cdTotal + 1;
	}
	
	else
	{
		cout << "Error: Exceeded the maximum of 100 CD's in the collection" << endl;
	}
	
		
}

>cdArray[num_cds].print(out);
cdArray is an array of char. cdArray[num_cds] is a char. char doesn't define any member functions. I'll let you figure out the rest of the errors, as they're the same thing.

I'm being dense today, because I'm still not getting it.

cdArray[num_cds].print(out);

print() is declared as a member function of the CDCollection class, meaning it should be called using an object of the CDCollection class or be used within the CDCollection class itself without explicit association with a CDCollection object. Unforturnately, in the above line you are trying to call print() using a variable of type char, the specific char being cdArray[num_cds]. However, print() won't work with an object of type char. It will only work with an object of type CDCollection. So, drop the cdArray[num_cds] and just call print(out).

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.