Visual Studio Ide for Arduino
https://www.visualmicro.com/forums/YaBB.pl
Visual Micro >> Installation & Troubleshooting >> Tip: Don't declare classes in .pde/.ino
https://www.visualmicro.com/forums/YaBB.pl?num=1320419623

Message started by CapnBry on Nov 4th, 2011 at 3:13pm

Title: Tip: Don't declare classes in .pde/.ino
Post by CapnBry on Nov 4th, 2011 at 3:13pm
I've got a PDE file that declares a class in it that compiles fine under Arduino but not in Visual Micro. Turns out the pde preprocessor doen't like classes inside .pde files because it adds forward declarations for class members.  Take this example.pde

[code]
class A
{
public:
  virtual void foo() {}
};

void setup()
{
}

void loop()
{
}
[/code]

This fails to compile with "virtual outside class declaration" because what is actually compiled adds a "virtual void foo();" above the class declaration. I'll submit this to codeplex but it is a gotcha that can emit any number of strange compiler errors, depending on what methods you have in your class. It confused the heck out of me because my class was actually a recursive template class definition which emitted a plethora of errors.

The solution is to define your classes in either a .h or .cpp file, which isn't preprocessed to add forward declarations.

Title: Re: Tip: Don't declare classes in .pde/.ino
Post by Visual Micro on Nov 4th, 2011 at 3:24pm
Thanks very much, we have had one other strange preprocessor report but the user failed to provide the code when asked.

This really helps, I guess it is the same issue. I'll have to look at the regex that is used to get the prototypes. It was originally copied from the arduino source so either we messed it up which is difficult to do or .net works slightly differntly to java.

Yes codeplex issue would be great thanks

Visual Studio Ide for Arduino » Powered by YaBB 2.5.2!
YaBB Forum Software © 2000-2019. All Rights Reserved.