Problem calling createReaderForCD


#1

I’m new to Juce, but I’ve got the demo program compiling under Visual Studio 2005, and and starting to get a bit of the hang of it.

I’m trying to make a CD player. As I understand it, in order to get things like the number of tracks, I need to create an instance of AudioCDReader. I would have thought it would be code like this:

AudioCDReader reader = AudioCDReader::createReaderForCD(selectedCDIndex);

However, when I try to compile this, I get error C2248: ‘juce::AudioCDReader::AudioCDReader’ : cannot access private member declared in class ‘juce::AudioCDReader’ y:\juce orig\extras\example projects\common\hellowarrencontentcomponent.cpp 198

I presume that it would be a mistake to alter any JUCE code blindly, so I’m guessing there must be a better way for me to get a reader. Am I right?

Thanks,
Warren


#2

AudioCDReader reader = AudioCDReader::createReaderForCD(selectedCDIndex);

That function returns a pointer; the left hand side of your code there has a stack object created! Change it to…

AudioCDReader* reader = AudioCDReader::createReaderForCD(selectedCDIndex);


#3

Thanks for that tip, that worked.

I’m on kind of a non-traditional learning path, I guess. Know Java and C#, trying to get up to speed on C++. So I’m still getting the hang of passing pointers instead of objects, and working without automatic garbage collection.

Can you answer one more dumb question about this? I see from the documentation that I will have to delete reader. That’s fine.

But if I have code like:
int tracks = reader->getNumTracks();
for (int i=1;i<=tracks;i++)
cboTracks->addItem(String(i),i);

do I have to delete all those strings that I’ve added? I’m thinking no, they’re anonymous variables but they’re on the stack, but my thinking could well be wrong. And if I clear the combo box? What happens to the orphaned Strings?

Thanks for reading this,
Warren


#4

you’re right, you don’t have to delete those.

You only need to ‘delete’ something when ‘new’ was used to create it.
For most of your code, you’ll be aware of this, as you’ll have written ‘new’ yourself. For the other times (when the ‘new’ is done within a function) you just have to use your memory (if you wrote the function yourself) or the documentation! [e.g. you saw in the docs that you need to delete reader].


#5

Thanks for the advice. It’s been really helpful.

Warren


#6