StandardCplusplus library: Creating vector of one class works, other doesn't.

Here's my code:

#include <stdlib.h>
#include <StandardCplusplus.h>
#include <vector>
#include <Wire.h>
#include <Adafruit_ADS1015.h>
#include <Adafruit_MCP4725.h>

using namespace std;

vector<Adafruit_ADS1115> adcs(4);
vector<Adafruit_MCP4725> dacs(2);

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  adcs[0] = new Adafruit_ADS1115(0x48);
  adcs[0].begin();
  adcs[1] = new Adafruit_ADS1115(0x49);
  adcs[1].begin();
  adcs[2] = new Adafruit_ADS1115(0x4A);
  adcs[2].begin();
  adcs[3] = new Adafruit_ADS1115(0x4B);
  adcs[3].begin();
  dacs[0] = new Adafruit_MCP4725;
  dacs[0].begin(0x62);
  dacs[1] = new Adafruit_MCP4725;
  dacs[1].begin(0x63);
} // setup

void loop()
{
} // loop

Here's the error message:

sketchbook/libraries/Adafruit_MCP4725/Adafruit_MCP4725.h:31:7: note: no known conversion for argument 1 from 'Adafruit_MCP4725*' to 'const Adafruit_MCP4725&'

Looking at the header files for the two classes, I don't see any major difference in the constructors. I don't see that I'm passing a pointer to anything here. I don't know what "argument 1" the error message is referring to in the first place. Putting parentheses after the class name like this doesn't change the results:

dacs[0] = new Adafruit_MCP4725();

Any ideas why the compiler treats these two differently? Thanks!

Try this:

dacs[0] = new Adafruit_MCP4725(0x4b);

Thanks for the reply, Isaac. As I suspected, that didn't work. The constructor doesn't take an argument. The bus address is passed to begin(). That's the bus address of one of the ADCs anyway. The ADCs appear to be initializing correctly.

Get rid of new.

Any ideas why the compiler treats these two differently? Thanks!

Because you call functions with parentheses EVEN IF YOU HAVE NOTHING TO PASS TO THEM.

vector<Adafruit_MCP4725> dacs(2);

That isn't a pointer so you can't use "new" to store it. Either remove "new" or make it a vector of pointers, eg.

vector<Adafruit_MCP4725 *> dacs(2);

If you do that, remember to delete the pointers when you are done with them (which conceivably is never).

Making the modification I suggested your sketch compiles without errors (note I had to change "." to "->" as the instances are now pointers):

#include <stdlib.h>
#include <StandardCplusplus.h>
#include <vector>
#include <Wire.h>
#include <Adafruit_ADS1015.h>
#include <Adafruit_MCP4725.h>

using namespace std;

vector<Adafruit_ADS1115 *> adcs(4);
vector<Adafruit_MCP4725 *> dacs(2);

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  adcs[0] = new Adafruit_ADS1115(0x48);
  adcs[0]->begin();
  adcs[1] = new Adafruit_ADS1115(0x49);
  adcs[1]->begin();
  adcs[2] = new Adafruit_ADS1115(0x4A);
  adcs[2]->begin();
  adcs[3] = new Adafruit_ADS1115(0x4B);
  adcs[3]->begin();
  dacs[0] = new Adafruit_MCP4725;
  dacs[0]->begin(0x62);
  dacs[1] = new Adafruit_MCP4725;
  dacs[1]->begin(0x63);
} // setup

void loop()
{
} // loop