Question: I get the following error for the code below, does anyone know why?
Problem:
I am working on a class (ClassB) that controls the behavior of a number of classes from an external library ( libmesh ). "... something ... part of the code is for setting some variables in these external library classes that have template functions.
I would like to be able to set some of these values ββfrom the constructor of the inheriting class (ClassC). But, if I do this, as in the code below, I get the error shown. If I remove this command in the constructor, it will be fine.
I also include a more detailed example that uses the same error but uses the libmesh class , this illustrates that I want to do a little better. I'm not sure about the benefits of what I'm trying to do, I basically want to know why this does not work, because it seems like it should be.
I found another similar entry, but I cannot apply it to my problem.
The problem of accessing the inner class of inheritance of template inheritance
Thanks for the help, Andrew
ERROR:
XXXXXXX@XXXXX:~/Documents/programs/build$ make test
[100%] Building CXX object CMakeFiles/test.dir/source/test.cpp.o
test.cpp: In constructor βClassC<T>::ClassC()β:
test.cpp:16:29: error: expected primary-expression before βintβ
test.cpp:16:29: error: expected β;β before βintβ
make[3]: *** [CMakeFiles/test.dir/source/test.cpp.o] Error 1
make[2]: *** [CMakeFiles/test.dir/all] Error 2
make[1]: *** [CMakeFiles/test.dir/rule] Error 2
make: *** [test] Error 2
SIMPLE CODE:
template <typename Type> class ClassB{
public:
ClassB(){}
template<typename TypeValue> void set_value(TypeValue value){
}
};
template<typename T> class ClassC : public ClassB<T>{
public:
ClassC(){
ClassB<T>::set_value<int>(1);;
}
};
int main (){
ClassC<double> c;
c.set_value<int>(1);
}
PROBLEM SPECIFIC CODE:
#include <string>
using std::string;
#include <libmesh.h>
#include <libmesh_common.h>
#include <equation_systems.h>
#include <transient_system.h>
#include <explicit_system.h>
#include <parameters.h>
#include <mesh.h>
using namespace libMesh;
template <typename Type> class EqCore{
public:
EqCore(EquationSystems& sys, string name) : eq_sys(sys){
name_.assign(name);
eq_sys.add_system<Type>(name_);
set_constant<double>("test4", 4);
}
template<typename ParamType> void set_constant(std::string name, ParamType var){
eq_sys.parameters.set<ParamType>(name) = var;
}
template<typename ParamType> ParamType get_constant(std::string name){
ParamType output = eq_sys.parameters.get<ParamType>(name);
return output;
}
EquationSystems& eq_sys;
string name_;
};
template <typename Type> class EqBase : public EqCore<Type>{
public:
EqBase(EquationSystems& sys, string name) : EqCore<Type>(sys, name){
EqCore<Type>::set_constant<double>("test5", 5);
}
};
int main (int argc, char** argv){
LibMeshInit init (argc, argv);
Mesh mesh;
EquationSystems eq_sys(mesh);
eq_sys.parameters.set<double>("test1") = 1;
printf("Test 1: %f\n", eq_sys.parameters.get<double>("test1"));
EqBase<TransientExplicitSystem> eq(eq_sys, "TestSystem");
eq.set_constant<double>("test2", 2);
printf("Test 2: %f\n", eq.get_constant<double>("test2"));
eq.eq_sys.parameters.set<double>("test3") = 3;
printf("Test 3: %f\n", eq.eq_sys.parameters.get<double>("test3"));
printf("Test 4: %f\n", eq.eq_sys.parameters.get<double>("test4"));
printf("Test 5: %f\n", eq.eq_sys.parameters.get<double>("test5"));
}