Welcome, Guest. Please Login or Register
Arduino IDE for Visual Studio
 
 
When Logging a Support Issue in the Forum, please ensure you have also:-
  • Enabled vMicro > Compiler > Show Build Properties and Verbose
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
Support requests without the output above may be impossible to answer, so please help us to help you
 
  HomeSearch Tutorials & Wiki visualmicro.com LoginHelpRegister  
 
Page Index Toggle Pages: 1
Send Topic Print
Question about code generated by "Add new Arduino Class and Header" (Read 117 times)
MarkH
Newbies
*
Offline



Posts: 2
Question about code generated by "Add new Arduino Class and Header"
May 15th, 2020 at 4:15pm
 
Hi.

Long-time C# hobbyist coder, long-time Arduino dabbler - now trying to get serious with OOP in Arduino...

So I'm curious about the .h and .cpp files generated by the "Add New Arduino Class and Header" menu item.

Three questions.

     1.  Why append the word "Class" at the end of the chosen class name?
     2.  Why auto-generate an init() function?
     3.  What is the purpose of the extern object at the end of both the .h and .ccp files?  None of the C++ class tutorials that I have come across do this - so I'm curious for the reason.

Looking back over the revision history, I see that these were very conscious choices and listed as revision features in revision 1208.19.

Thanks for indulging the vMicro-noob questions.

Mark
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10653
United Kingdom
Re: Question about code generated by "Add new Arduino Class and Header"
Reply #1 - May 15th, 2020 at 5:15pm
 
Hi,

Good questions and maybe we can extend the new item examples to show more flexibility and clarity.

You can create .cpp/h files in anyway that you choose. Our exmple has been designed to show how Arduino often implements a class and then makes it globally available to the code (via core or #include).

Our example implements the same logic to create and instantiate a class as does the Arduino AVR "Serial" class. Some boards have just Serial and some have Serial, Serial1, Serial2 etc. Each is instantiated at startup and extern applied. Then accessed via code as Serial.println("Hello world") or Serial2.println("Hello world")

Some people prefer static classes and in many cases you might want to instantiate objects only in the code that actually uses them. Then you do not need externa.

It is entirely up to you and please do submit any recomended alternative "New Item" templates that you believe would be useful for Visual Micro to implement.

The init() is simply an example to show less experinced users how they might add a method to initialise some base values for their class. Again you can use standard c++/arduino/gcc and entirely ignore our example in part or entirity.

Quote:
Looking back over the revision history, I see that these were very conscious choices and listed as revision features in revision 1208.19.

I am unclear as to what prompted this question exactly or how to answer...

There was "library versioning" released last year. You can create arduino libraries of your own by following the arduino guidelines or looking at how existing libraries are structured.

The arduino libraries carry version numbering facility in an external text file called library.properties. We build on that system to provide a more fluent way to use different versions of the same libraries accross multiple projects.

Normally, for arduino, you can only have one library version installed at one time.  Therefore, when you enable the facility to use different library versions your code might not then compile in the arduino ide (depends which version of a lib the arduino ide actually thinks is installed).

Libraries are effectively just a few .cpp and .h files. However, they do not have access to the project code. The project has access to library code not the otherway around. A library can also use code from other libraries.

I hope this helps.

Back to top
 
WWW  
IP Logged
 
MarkH
Newbies
*
Offline



Posts: 2
Re: Question about code generated by "Add new Arduino Class and Header"
Reply #2 - May 18th, 2020 at 1:43pm
 
Hi Tim,

Thank you for the information/explanation - makes sense as stating-point and as example of how one could proceed.

I like how the Add New Class code creates both .h and .cpp file and also puts the #include in the .ino file - nice and helpful.

As a coding style, I have never used the word "Class" in my class names - but that is minor and can be easily dealt with... I spent the weekend digging around the installed template files and on the Visual Studio docs for creating templates - an interesting read that might prove the way for me to go sometime down the road...

At any rate, just to clarify - the revision history that I was referring to was Visual Micro's own revision history of the VM product - not any sort of "library versioning" https://www.visualmicro.com/page/Visual-Micro-Product-Version-History-Fixes-and-... - towards the very bottom of the page... 

Thanks again for the response and the information.   I'm finding the product to be very helpful.

Mark

Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10653
United Kingdom
Re: Question about code generated by "Add new Arduino Class and Header"
Reply #3 - May 18th, 2020 at 2:26pm
 
Great thanks for the update.

Our templates use the "Class" in the name only to try to create something automatically and demo the difference between class and instantiated objects to less experienced users.

You can rename or not add the "Class" but sounds like you have moved onto better things with your own understanding of templates  Smiley

Good to hear the product is useful for you. Thanks
Back to top
 
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print