Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Class & Extern question (Read 2241 times)
Bob Jones
Full Member
***
Offline


Posts: 210
Location: Bellingham, WA
Joined: Dec 4th, 2015
Class & Extern question
Jul 31st, 2018 at 7:51pm
Print Post  
If I generate a new class named foo, the generated code looks like this:

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

extern FooClass Foo;
 


Code (C++)
Select All
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
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Class & Extern question
Reply #1 - Jul 31st, 2018 at 9:52pm
Print Post  
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: 210
Location: Bellingham, WA
Joined: Dec 4th, 2015
Re: Class & Extern question
Reply #2 - Jul 31st, 2018 at 11:37pm
Print Post  
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
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Class & Extern question
Reply #3 - Aug 3rd, 2018 at 7:04pm
Print Post  
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
Select All
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 TopicPrint