VS Arduino
Visual Micro >> General Board >> Class & Extern question
https://www.visualmicro.com/forums/YaBB.pl?num=1533066696

Message started by Bob Jones on Jul 31st, 2018 at 7:51pm

Title: Class & Extern question
Post by Bob Jones on Jul 31st, 2018 at 7: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?


Title: Re: Class & Extern question
Post by Visual Micro on Jul 31st, 2018 at 9: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.

Title: Re: Class & Extern question
Post by Bob Jones on Jul 31st, 2018 at 11:37pm
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

Title: Re: Class & Extern question
Post by Visual Micro on Aug 3rd, 2018 at 7: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;[/code]

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.

VS Arduino » Powered by YaBB 2.6.12!
YaBB Forum Software © 2000-2024. All Rights Reserved.