Hello All,
I am trying to write a program for my Arduino Nano with the following structure: A mastermind .ino file which calls functions from a number of .cpp/.h files in the same directory. So far I have been trying to get my testing mastermind file to include one of my testing .cpp/.h files, and have run into some issues, I think because the .h file for my secondary file uses an array of function pointers.
The file names are Testing3.ino, t3p0.cpp, and t3p0.h
I ran into a bunch of issues getting my array of function pointers working, and finally found a method (by reading a number of forums, this one included) that I believe will work. The issue I have now is that when I try to compile my master file, I get a multiple definition error for my array of function pointers.
The error seems like the kind I would expect if I did not have include guards in my t3p0.h file, which I do have. I have included code snippets of the method for creating an array of function pointers that I believe should work, as well as a screen shot of the error method I get when I attempt to compile. I have deleted the other (commented out) methods I tried to use for creating an array of function pointers, but I can provide them if they may be of assistance.
Right now the code doesn't actually do anything, that will come later. I am adapting code I already wrote to work in a method I find more elegant/less hacky.
Testing3.ino:
#include "t3p0.h"
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
t3p0.cpp:
#include "t3p0.h"
void pat0::p0_s0(){
}
void pat0::p0_s1(){
}
void pat0::p0_s2(){
}
t3p0.h:
/*
* t3p0.h
*
* Created on: Dec 13, 2018
* Author:
*/
#ifndef T3P0_H_
#define T3P0_H_
class pat0
{
public:
void p0_s0(); // Function for state 0 of pattern 0.
void p0_s1(); // Function for state 1 of pattern 0.
void p0_s2(); // Function for state 2 of pattern 0.
};
typedef void (pat0::*pat0fn)(); //typedef used for an array of function pointers within pat0 class
pat0fn pat0_array[3] = {&pat0::p0_s0, &pat0::p0_s1, &pat0::p0_s2}; // array of function pointers within
//pat0 class.
#endif /* T3P0_H_ */
and finally the error I get when attempting to compile (attached):
Has anyone encountered this before? I feel like I am missing something very basic but haven't been able to find a similar enough situation on this and other forums.
I very much appreciate any help and insight folks can offer.
