Instantiating a class defined in a single cpp-file


#1

I would like to add an OpenGl canvas to the JuceAudioPlugin project. Right now I’m trying to port the OpenGl
demo from the JUCE demo directly. One thing that confuses me is that the OpenGlDemo class is written in a single cpp-file
and not partitioned in a header and a cpp file. I can get the canvas to “work” when I create the class using the *.h and *.cpp
files. When I try to instantiate the OpenGlDemo using the “one-file-approach” I get the following errors:

c:\jucedevel\juceaudioplugin\demo\src\DemoEditorComponent.h(86) : error C2143: syntax error : missing ';' before '*' c:\jucedevel\juceaudioplugin\demo\src\DemoEditorComponent.h(86) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\jucedevel\juceaudioplugin\demo\src\DemoEditorComponent.h(86) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\..\src\DemoEditorComponent.cpp(76) : error C2065: 'gl' : undeclared identifier ..\..\src\DemoEditorComponent.cpp(76) : error C2061: syntax error : identifier 'createOpenGLDemo'
line 86 refers to the declaration of the OpenGlDemo pointer which reads:

which I use in the DemoEditComponent.cpp as such :

Can anyone please tell me what the problem is (I hope I’m not missing any information here :slight_smile: )

Also, I’m instantiating the OpenGlDemo in the DemoEditorComponent.cpp (which I believe is correct) but how does the compiler
know where to look when I cannot include the class-cpp file (I’m only used to including header files)? Really curious to know the answer :slight_smile:

Hope to get some answers - and that I have made myself clear

Cheers


#2

why are you worried about this? just use two files! :slight_smile:


#3

I think a c++ reference book would explain this kind of thing more clearly than we could!


#4

It’s just for curiousity since I’m fairly green with C++ and need to demistify some of the methods I don’t understand. I tried to google the answer but couldn’t find any useful information and since I’ve only seen this approach in the JuceDemo I felt the reason to ask here.

Also, I find it practically to only have one file per class - why use two files when you can get away with only one?

I clearly see that I was out of line :?


#5

You weren’t out of line! Separate headers are needed if you’re sharing the same class from different bits of code, but whenever I just need a simple, private class that doesn’t have circular references to other ones, I prefer to use an inline one because it’s easier to see what’s going on.


#6

Thanks for you answer

Merry Christmas
Thomas :slight_smile:


#7