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 Tip: Don't declare classes in .pde/.ino (Read 4435 times)
CapnBry
Junior Member
**
Offline


Posts: 32
Joined: Nov 4th, 2011
Tip: Don't declare classes in .pde/.ino
Nov 4th, 2011 at 3:13pm
Print Post  
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
Select All
class A
{
public:
  virtual void foo() {}
};

void setup()
{
}

void loop()
{
}
 



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.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Tip: Don't declare classes in .pde/.ino
Reply #1 - Nov 4th, 2011 at 3:24pm
Print Post  
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
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint