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 Problem with using C++ template for generic types in *.ino files (VS 2019) (Read 1506 times)
Someguy
Newbies
*
Offline


Posts: 3
Joined: Aug 30th, 2020
Problem with using C++ template for generic types in *.ino files (VS 2019)
Aug 30th, 2020 at 5:03pm
Print Post  
Hi all,

I have purchase a license for VisualMicro so I could do some hardware debugging with my Arduino DUE. So far everything is great. However, today I encountered some weird issues with VisualMicro.

This sketch can't be complied in VisualMicro but compile in Arduino IDE just fine. It also seems that many template declaration approach yields similar result. It can only be fixed by moving "someFunc" to a seperate Header.h

template <class  T>
void someFunc(T& result) {

}

void setup() {

}

void loop() {
    byte result = 0;
    someFunc(result);
}

Here is compile message from VisalMicro on Visual Studio 2019

Compiling debug version of 'Sketch2' for 'ATmega2560 (Mega 2560) (Arduino Mega)'
 
Sketch2.ino: 5:11: error: declaration of template parameter 'T' shadows template parameter
Sketch2.ino:3: note  template parameter T declared here
   template <class  T>
   ^~~~~
 
Sketch2.ino: 5:24: error: too many template-parameter-lists
 
Sketch2.ino: 4:15: error: variable or field 'someFunc' declared void
   void someFunc(T& result) {
 
Sketch2.ino: 4:15: error: 'T' was not declared in this scope
 
Sketch2.ino: 4:18: error: 'result' was not declared in this scope
   void someFunc(T& result) {
   ^~~~~~
 
Sketch2.ino: In function void loop()
 
Sketch2.ino: 14:1: error: 'someFunc' was not declared in this scope
   someFunc(result)
   ^   ~~~~
Error compiling project sources
Debug build failed for project 'Sketch2'

It is a little inconvenience ? Has anyone encounter similar issues ? Thank everyone so much ! 

Quick update: It also seems that moving 'someFunc' to a seperate *.ino file works too. 
« Last Edit: Aug 30th, 2020 at 5:13pm by Someguy »  
Back to top
 
IP Logged
 
Someguy
Newbies
*
Offline


Posts: 3
Joined: Aug 30th, 2020
Re: Problem with using C++ template for generic types in *.ino files (VS 2019)
Reply #1 - Aug 30th, 2020 at 5:23pm
Print Post  
Second update: It works if I move 'someFunc' below setup(). I guess it's just a minor bug. 

void setup() {

}

template <class  T>
void someFunc(T& result) {

}

void loop() {
    byte result = 0;
    someFunc<byte>(result);
}
  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2174
Joined: Feb 13th, 2019
Re: Problem with using C++ template for generic types in *.ino files (VS 2019)
Reply #2 - Sep 2nd, 2020 at 6:35pm
Print Post  
In the latest forum release (20.07.08.13) this issue should now be resolved, and it can be downloaded from the top of the below board:
https://www.visualmicro.com/forums/YaBB.pl?board=VS_ARDUINO_EXT_RELEASES

If you haven't installed one of the forum releases before, further help is below:
Documentation - See Section 2. Install Visual Micro
Walkthrough Video on YouTube

Let us know if you encounter any further issues, and thanks again for the clear reporting.
  
Back to top
 
IP Logged
 
Ridge_glider
Newbies
*
Offline


Posts: 1
Joined: Sep 1st, 2020
Re: Problem with using C++ template for generic types in *.ino files (VS 2019)
Reply #3 - Sep 2nd, 2020 at 9:01pm
Print Post  
I had a similar problem with templates that rearranging the function order as 'Someguy' suggested did not cure. However, the new release seems to solve it. Thanks!
  
Back to top
 
IP Logged
 
Someguy
Newbies
*
Offline


Posts: 3
Joined: Aug 30th, 2020
Re: Problem with using C++ template for generic types in *.ino files (VS 2019)
Reply #4 - Sep 5th, 2020 at 8:02am
Print Post  
Thank you all! Everything seem working properly in latest version.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint