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
Class & Extern question (Read 596 times)
Bob Jones
Full Member
***
Offline



Posts: 207
Bellingham, WA
Class & Extern question
Jul 31st, 2018 at 8:51pm
 
If I generate a new class named foo, the generated code looks like this:

in Foo.h:
Code (C++):
class FooClass {
 protected:
 public:
	void init();
};

extern FooClass Foo;
 


Code (C++):
in Foo.cpp:
void FooClass::init() { }

FooClass Foo;
 



My questions are:
1) Why is "Class" added to the class name?
2) What would the extern statement look like if I remove "Class" from the class name? extern foo foo; doesn't work.
3) How can I change what is generated? Is there a template I can modify?

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



Posts: 10395
United Kingdom
Re: Class & Extern question
Reply #1 - Jul 31st, 2018 at 10:52pm
 
Sorry this forum is not for syntax and general coding discussion.

Visual Micro does have some options such as add>item that creates cpp/h class as an example, there is also a File>New example and a lot of the arduino core also uses classes so you can look at those.

You might question why you have defined Foo twice.
Back to top
 
WWW  
IP Logged
 
Bob Jones
Full Member
***
Offline



Posts: 207
Bellingham, WA
Re: Class & Extern question
Reply #2 - Aug 1st, 2018 at 12:37am
 
Tim,

This is not a general programming question. It is about the specific behavior of VM when adding a new class with header. Why does it change the name of the class from what I ask (e.g. Foo) to FooClass?

It turns out this is highly related to the problem I am trying to solve about inheritance, so I do need to understand why FooClass is different from Foo.

Thanks,

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



Posts: 10395
United Kingdom
Re: Class & Extern question
Reply #3 - Aug 3rd, 2018 at 8:04pm
 
I see. That function is just a helper function creates classes in a similar way to many that are used in the arduino cores.

You can create classes however you like. You can also use the standard visual studio "add new item > class" which uses a wizard to allow you to specify options. As long as all the options are arduino/gcc compatible then they are fine to use.

You can also add your own "new item" templates that create file(s) containing whatever you like. It's worth reading up on Visual Studio Item templates they are very powerful.

The example that you mention allows users to more obviously create multiple versions of the class. For example if you had ButtonClass and your project had 4 buttons you could create 4 instances very easily.

Code:
ButtonClass Button1;
ButtonClass Button2;
ButtonClass Button3;
ButtonClass Button4; 



The example works similar to HardwareSerial in the avr core which might provide Serial, Serial1, Serial2 etc. all based on HardwareSerial.

There are plenty of Gcc C++ combinations and Visual Micro has no control over how any are compiled it just passed source code paths to the compiler specified by your board core.
Back to top
 
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print