Thread: multisets?

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    85

    multisets?

    so i declared a multiset header in my class declaration:

    Code:
    private:
    	multiset<MediaRecord>mySongs;
    	multiset<MediaRecord>::iterator blah;
    then in my member functions I wonna do stuff like:
    Code:
    bool MediaPlayer::saveFile(const string& filename){
    	
    	ofstream outfile(filename.c_str());
    
    	if ((outfile << "#CS201PLAYLISTFILE2#" << endl)){
    		for(blah = mySongs.begin(); blah != mySongs.end(); blah++){ 
    			outfile <<endl<< *blah->getTitle() << endl 
    					<< *blah->getAuthor() << endl 
    					<< *blah->getGenre() << endl 
    					<< *blah->getLength() <<endl;
    					cout<<"\nsave successful\n";
    		return true;
    	}
    	return false;
    }
    but i'm getting errors like:

    'std::iterator' : use of class template requires template argument list
    error C2501: 'MediaPlayer::multiset' : missing storage-class or type specifiers
    error C2143: syntax error : missing ';' before '<'

    where I declared the multiset and

    error C3861: 'blah': identifier not found, even with argument-dependent lookup

    where I try to use the interator.

    am I missing something? do i need to include a file to use the multiset template? or is this completely wrong?

    sorry if this is a dumb question...

  2. #2
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    First, you seem to be missing a closing brace (or you have an extra opening brace) for your for loop.

    Second, since your set holds MediaRecord objects, you only need one indirection from the iterator to access the object. So try either (*blah).getTitle() or blah->getTitle().

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    85
    thanks that doesn't seem to be the main problem though. I'm still getting errors where I create the multiset and on the line with the for loop...

  4. #4
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    I think you'll have to post more code. I setup a dummy program with that code and the changes I suggested. I was able to get it to compile and run correctly.

    Also, make sure that you #include <set> and since you aren't using "std::" add "using std::multiset" in your header file. The using declaration is a bit of bad form in a header file, but it might just fix your problem.

Popular pages Recent additions subscribe to a feed