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 Error: No suitable constructor exists to convert from "int" to "ButtonClass" (Read 7701 times)
deangelo
Newbies
*
Offline


Posts: 9
Joined: Mar 20th, 2016
Error: No suitable constructor exists to convert from "int" to "ButtonClass"
Mar 20th, 2016 at 4:08pm
Print Post  
Hello everyone.

I'm trying compile a code for Arduino Uno with Visual Micro, but I get a error in slice of code:

In my project, in the file LibProt.ino,

...
ButtonClass CVB(7);
...

Error: No suitable constructor exists to convert from "int" to "ButtonClass"

The error appear in the argument of CVB, in the 7.



My ButtonClass is:


//Button.h

#ifndef _BUTTON_h
#define _BUTTON_h

#if defined(ARDUINO) && ARDUINO >= 100
     #include "arduino.h"
#else
     #include "WProgram.h"
#endif

class ButtonClass
{
protected:
      uint8_t pinButton;
      byte stateRead_1;

public:
      void Button(uint8_t pin);
      bool readButton();
};

extern ButtonClass Button;

#endif



And


//Button.cpp

#include "Button.h"

//Constructor
void ButtonClass::Button(uint8_t pin)
{
     pinButton = pin;
     stateRead_1 = LOW;

     pinMode(pinButton, OUTPUT);
}

bool ButtonClass::readButton()
{
     //Code...
}

ButtonClass Button;


I have researched a lot about it.
I tried to write in different ways, but did not get a solution.
Can someone help me?
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12138
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Error: No suitable constructor exists to convert from "int" to "ButtonClass"
Reply #1 - Mar 20th, 2016 at 8:19pm
Print Post  
Don't you just want to call the button method?

Code
Select All
void setup()
{
    Button.Button(7);
} 

« Last Edit: Mar 20th, 2016 at 8:20pm by Tim@Visual Micro »  
Back to top
IP Logged
 
deangelo
Newbies
*
Offline


Posts: 9
Joined: Mar 20th, 2016
Re: Error: No suitable constructor exists to convert from "int" to "ButtonClass"
Reply #2 - Mar 20th, 2016 at 8:56pm
Print Post  
Tim@Visual Micro wrote on Mar 20th, 2016 at 8:19pm:
Don't you just want to call the button method?

Code
Select All
void setup()
{
    Button.Button(7);
} 



I have three buttons and need to save the state of each.
And each of the objects (button1, button2 and button3) need to be global.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12138
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Error: No suitable constructor exists to convert from "int" to "ButtonClass"
Reply #3 - Mar 20th, 2016 at 9:18pm
Print Post  
So you need

extern ButtonClass Button1;
extern ButtonClass Button2;
extern ButtonClass Button3;

or you need a constructor for ::ButtonClass(int) and to create objects from ButtonClass and not use ::Button()
« Last Edit: Mar 20th, 2016 at 9:19pm by Tim@Visual Micro »  
Back to top
IP Logged
 
deangelo
Newbies
*
Offline


Posts: 9
Joined: Mar 20th, 2016
Re: Error: No suitable constructor exists to convert from "int" to "ButtonClass"
Reply #4 - Mar 20th, 2016 at 9:28pm
Print Post  
Tim@Visual Micro wrote on Mar 20th, 2016 at 9:18pm:
So you need

extern ButtonClass Button1;
extern ButtonClass Button2;
extern ButtonClass Button3;

or you need a constructor for ::ButtonClass(int) and to create objects from ButtonClass and not use ::Button()


You're right.

I found my mistake.

I believe that confuses OOP concepts of C++ with Java.

Thank you for the support.

Wink
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint