Toolbar::addDefaultItems() won't accept my factory


#1

Based on the demo toolbar I tried the following:

Code in private section of GUI.h

juce::Toolbar topToolbar;

class CustomToolbarItemFactory : juce::ToolbarItemFactory {

public:
	CustomToolbarItemFactory() {};

	void getAllToolbarItemIds(juce::Array<int>& ids) override {
		ids.add(1);
	}

	void getDefaultItemSet(juce::Array<int>& ids) override {
		ids.add(1);
	}

	juce::ToolbarItemComponent* createItem(int itemid) override {
		if (itemid == 1)
			return new juce::ToolbarButton(itemid, "", juce::Drawable::createFromImageData(BinaryDataStorage::fit_to_win_png, BinaryDataStorage::fit_to_win_pngSize), 0);
		return 0;
	}

};

CustomToolbarItemFactory factory;

code in GUI constructor (GUI.cpp)

addAndMakeVisible(topToolbar);
topToolbar.addDefaultItems(factory);

But this line: topToolbar.addDefaultItems(factory); gives me this error:

Error: Conversion is inaccessible base class “juce::ToolbarItemFactory” is not allowed. Any idea what’s wrong?


#2

OOOh nevermind just realized I forgot public keyword lol


#3

I changed to:

  class CustomToolbarItemFactory : public juce::ToolbarItemFactory {

but now I get another error:

Error: ‘GUI’: cannot instatiate abstract class


#4

Okay that was another stupid mistake.