Am I blind?

Hi All,

The following code fails with
“error C2512: ‘JK_Clipboard’ : no appropriate default constructor available”
only if I try to make it a singleton class and I don’t understand why.
It compiles w/o any problem if not a singleton.

#include "juce.h"

class JK_Clipboard  :	public ListBox,
				public ListBoxModel,
				public DeletedAtShutdown
                           
{
public:
	//==============================================================================
    	JK_Clipboard (const String &componentName, int rowCount);
    	~JK_Clipboard();

	juce_DeclareSingleton (JK_Clipboard, false)

	//===============================================================================
int  getNumRows();
    	void paintListBoxItem( int rowNumber, Graphics& g, int width, int height, bool rowIsSelected );

    	//==============================================================================
    	juce_UseDebuggingNewOperator

private:

	int _rowCount;
	
	
	//==============================================================================
    	// (prevent copy constructor and operator= being generated..)
    	JK_Clipboard (const JK_Clipboard&);
    	const JK_Clipboard& operator= (const JK_Clipboard&);
};

I would like to skip singleton here but I need to have acces to its instance but it
is inside a tabcontrol!

fileManagerTabComponent->addTab (T(“Tab1”), Colour (0xd3d3d3), new JK_Clipboard (T(“Clipboard”), 100), true);

What goes wrong here?

Thank you for your help!
Joerg

You seem rather muddled.

Like the error says, your class has no default constructor, so obviously the singleton code won’t compile, because it has no way of actually creating one.

(And the fact that something is in a tab box is no reason to use a singleton…)

I understood that, thank you Jules!

But how can I get the instance of the class out of the tabcontrol?
I don’t want to make it a singleton!
I apologize for these beginner questions!

Joerg

Why not something like:

JK_Clipboard* theJkClipboard;
theJkClipboard = new JK_Clipboard (T("Clipboard"), 100);
fileManagerTabComponent->addTab (T("Tab1"), Colour (0xd3d3d3), theJkClipboard, true);

You now have access to the instance thru theJkClipboard…

Of course, this would work but i am using Jucer and I have to follow the jucer rules sometimes
to keep readable by jucer.

Thank you anyway!

Joerg

Found it!

instance = dynamic_cast <ListBox*> (TabComponent->getTabContentComponent(index));

I’ve overseen getTabContentComponent!

Joerg

Jucer components can have custom constructor parameters, so you can always set them up to take things like this if necessary.

[quote=“Joerg Koehler”]Found it!

instance = dynamic_cast <ListBox*> (TabComponent->getTabContentComponent(index));

I’ve overseen getTabContentComponent!

Joerg[/quote]

Don’t forget to do a null check since you are doing dynamic_cast.

Yes, I do!

Thank you!
Joerg

U can make singleton class by ur own. U need not to follow JUCE way only.