Working with the MCP23017, C++ & embedding in a new class

I have successfully used the MCP23017-RK library with a simple program. However, I would like to create some high level functionality on top of it with my own C++ class. However, I am having trouble getting the very basic declaration to compile. The error message I receive is

In file included from ../wiring/inc/spark_wiring_fuel.h:33,
                 from ./inc/application.h:47,
                 from ./inc/Particle.h:5,
                 from /Users/name/src/NewBusFirmware.cpp:5:
../wiring/inc/spark_wiring_i2c.h:149:14: error: '__fetch_global_Wire' is not a type

My C++ class looks like the following:

#ifndef __NAND7400_H
#define __NAND7400_H
#include "MCP23017-RK.h"
#include "Particle.h"
#include "application.h"
class NAND7400 {
    private:
        MCP23017 data(Wire, 0);  // offending line, which is fine when declared in a c function
    public:
        NAND7400();
};
#endif

Any thoughts would be greatly appreciated.

When using a class with a required constructor parameters as a member variable, I usually do it like this:

class NAND7400 {
    private:
        MCP23017 data;
    public:
        NAND7400();
};

NAND7400::NAND7400() : data(Wire, 0) {    
}

The variable declaration in the class does not have the parameters, and instead the constructor parameters are passed in the implementation of the outer class constructor.

worked perfectly, thanks @rickkas7

1 Like