Getting mad with dynamic_cast and related errors

I am prting one of my 0.6 modules wich uses a “context menu”

I have the following code and always get the same error:

error: use of undeclared identifier ‘module’
DrumSampler DrumSampler = dynamic_cast< struct DrumSampler>(module)




void appendContextMenu(Menu *menu)  {
	

	MenuLabel *spacerLabel = new MenuLabel();
	menu->addChild(spacerLabel);

	DrumSampler *DrumSampler = dynamic_cast< struct DrumSampler*>(module);
	assert(DrumSampler);

	DrumSamplerItem0 *sampleItem0 = new DrumSamplerItem0();
	sampleItem0->text = "Load sample 01";
	sampleItem0->rightText += (DrumSampler->fileLoaded[0] == true) ? "✔" : "";
	sampleItem0->DrumSampler0 = DrumSampler;
	menu->addChild(sampleItem0);


	DrumSamplerItem1 *sampleItem1 = new DrumSamplerItem1();
	sampleItem1->text = "Load sample 02";
	sampleItem1->rightText += (DrumSampler->fileLoaded[1] == true) ? "✔" : "";
	sampleItem1->DrumSampler1 = DrumSampler;
	menu->addChild(sampleItem1);


	DrumSamplerItem2 *sampleItem2 = new DrumSamplerItem2();
	sampleItem2->text = "Load sample 03";
	sampleItem2->rightText += (DrumSampler->fileLoaded[2] == true) ? "✔" : "";
	sampleItem2->DrumSampler2 = DrumSampler;
	menu->addChild(sampleItem2);


	DrumSamplerItem3 *sampleItem3 = new DrumSamplerItem3();
	sampleItem3->text = "Load sample 04";
	sampleItem3->rightText += (DrumSampler->fileLoaded[3] == true) ? "✔" : "";
	sampleItem3->DrumSampler3 = DrumSampler;
	menu->addChild(sampleItem3);


	DrumSamplerItem4 *sampleItem4 = new DrumSamplerItem4();
	sampleItem4->text = "Load sample 05";
	sampleItem4->rightText += (DrumSampler->fileLoaded[4] == true) ? "✔" : "";
	sampleItem4->DrumSampler4 = DrumSampler;
	menu->addChild(sampleItem4);


	DrumSamplerItem5 *sampleItem5 = new DrumSamplerItem5();
	sampleItem5->text = "Load sample 06";
	sampleItem5->rightText += (DrumSampler->fileLoaded[5] == true) ? "✔" : "";
	sampleItem5->DrumSampler5 = DrumSampler;
	menu->addChild(sampleItem5);


	DrumSamplerItem6 *sampleItem6 = new DrumSamplerItem6();
	sampleItem6->text = "Load sample 07";
	sampleItem6->rightText += (DrumSampler->fileLoaded[6] == true) ? "✔" : "";
	sampleItem6->DrumSampler6 = DrumSampler;
	menu->addChild(sampleItem6);


	DrumSamplerItem7 *sampleItem7 = new DrumSamplerItem7();
	sampleItem7->text = "Load sample 08";
	sampleItem7->rightText += (DrumSampler->fileLoaded[7] == true) ? "✔" : "";
	sampleItem7->DrumSampler7 = DrumSampler;
	menu->addChild(sampleItem7);


}

Based on the indention of appendContextMenu(), it looks like it’s a root-level function instead of a class method. You need to place it inline in a class or call it DrumSampler::appendContextMenu().
Also, DrumSampler *DrumSampler doesn’t look like it’ll work because you’re using the same name for the variable as the type. Call it drumSampler or something.

was working in 0.6 but not in 1.0…

if I move it inside the class i get:

error: function definition is not allowed here
void appendContextMenu(Menu *menu){

Also, dynamic_cast< struct DrumSampler*>(module) doesn’t look good, loose the struct

Looks like you have a github repository for it. Would be much easier to help, if you would just commit the current status, so that others can run “make” on it. I think Andrew even offered to port plugins and send pull requests to make it work for 1.0. But don’t forget to run astyle or similar tools on it, the formatting looks really bad.

well, my github repo is a real mess, and it’s stuck at version 0.5 I believe…and this plug is not open-sourced

Good time to clean up your repository. And if it is free, why not releasing it as open source? You already kind of released it in the pastebin in your Facebook posting :slightly_smiling_face:

I know, but it it’s a suite of modules… However, I see what I can come up with :wink: and thanks for this “astyle” suggestion

weel, it really lloks like my code was a complete mess…voids and structs out of the main struct…
I had a look at Unity module in the Fundamental and reworked my code to follw the same structure…and it worked !!!

Thanks guys for helping me find the right direction :wink:

1 Like

Btw, struct Foo* is a syntax maintained for C compatibility in C++. Normally you’d just write Foo*.