I’m working on a larger project with both Cores and Photons and we have a base class with a number of child classes. The base class has a method called update which pretty much just calls another pure virtual method called doUpdate. Each of the child classes implements doUpdate and none of them implement update.
With that said, we’d like to be able to do as the reference docs do and add a Spark.function within the constructors of those child classes.
The constructor, etc. essentially looks like this:
// ChildClassName.cpp
OurNamespace::ChildClassName:ChildClassName(...) : OurNamespace::BaseClassName(...) {
// Bunch of initialization
Spark.function("a_function_name", &OurNamespace::ChildClassName::update, this);
}
...
int OurNamespace::ChildClassName:doUpdate(String args) {
// do whatever
}
// BaseClassName.cpp
int OurNamespace::BaseClassName:update(String args) {
// do whatever
return doUpdate(args);
}
Now when I try to compile this, I get errors similar to this:
OurNameSpace_ChildClassName.cpp: In constructor 'OurNameSpace::ChildClassName::ChildClassName(int, std::list<int>*)':
OurNameSpace_ChildClassName.cpp:45:80: error: no matching function for call to 'CloudClass::function(const char [7], int (OurNameSpace::BaseClassName::*)(String), OurNameSpace::ChildClassName*)'
Spark.function("ChildClassName_1", &OurNameSpace::ChildClassName::update, ((OurNameSpace::ChildClassName*)this));
^
OurNameSpace_ChildClassName.cpp:45:80: note: candidates are:
In file included from ../wiring/inc/spark_wiring.h:46:0,
fCompile failed. Exiting.
rom ./inc/application.h:36,
from OurNameSpace_BaseClassName.h:15,
from OurNameSpace_Thermostat.h:14,
from OurNameSpace_ChildClassName.h:14,
from OurNameSpace_ChildClassName.cpp:1:
../wiring/inc/spark_wiring_cloud.h:52:17: note: static bool CloudClass::function(const char*, int (*)(String))
static bool function(const char *funcKey, user_function_int_str_t* func)
^
../wiring/inc/spark_wiring_cloud.h:52:17: note: candidate expects 2 arguments, 3 provided
../wiring/inc/spark_wiring_cloud.h:57:17: note: static bool CloudClass::function(const char*, user_std_function_int_str_t, void*)
static bool function(const char *funcKey, user_std_function_int_str_t func, void* reserved=NULL)
^
../wiring/inc/spark_wiring_cloud.h:57:17: note: no known conversion for argument 2 from 'int (OurNameSpace::BaseClassName::*)(String)' to 'user_std_function_int_str_t {aka std::function<int(String)>}'
../wiring/inc/spark_wiring_cloud.h:75:17: note: template<class T> static void CloudClass::function(const char*, int (T::*)(String), T*)
static void function(const char *funcKey, int (T::*func)(String), T *instance) {
^
../wiring/inc/spark_wiring_cloud.h:75:17: note: template argument deduction/substitution failed:
OurNameSpace_ChildClassName.cpp:45:80: note: deduced conflicting types for parameter 'T' ('OurNameSpace::BaseClassName' and 'OurNameSpace::ChildClassName')
Spark.function("ChildClassName_1", &OurNameSpace::ChildClassName::update, ((OurNameSpace::ChildClassName*)this));
^
make[1]: *** [../build/target/user/platform-6OurNameSpace_ChildClassName.o] Error 1
make: *** [user] Error 2
-- Configuring done
-- Generating done
-- Build files have been written to: /some/place
Now, I’ve tried casting the this
to see if it helps and I get the same thing. Also note that I’m only instantiating a single copy of this child class, so I don’t think that the string not being unique is the issue either (I would think it wouldn’t be regardless as these are compiler errors not runtime errors, anyhow). Additionally, I run into this no matter whether I’m compiling for Core or for Photon.
Any suggestions?