But, if I am programming the component member to perform the initialization, I don't need a function pointer, so passing one in is meaningless. Is this just an unfortunate consequence or is the pointer actually going to be used in some other capacity?
Thanks, Andrew On Wed, Jun 27, 2012 at 4:24 PM, John Peterson <[email protected]> wrote: > On Wed, Jun 27, 2012 at 2:11 PM, Andrew E Slaughter > <[email protected]> wrote: > > If I understand correctly, if my initialization is expensive then it > should > > be coded directly into the component member of a class derived from > > AnalyticFunction, as follows. Then simply use the project_solution and > skip > > the add_initial_function(...) and init() commands for the system. Is this > > correct? > > > > class AnalyticFunctionTest : public AnalyticFunction<Number>{ > > public: > > AnalyticFunctionTest(){ > > _initialized = true; > > } > > > > Number component(unsigned int i, const Point& p, Real time = 0){ > > if (i == 0){ > > return 1; > > } else { > > return 2; > > } > > } > > }; > > > > I tried using this, but I get an error b/c I believe that > AnalyticFunction > > needs a default constructor > > (http://www.cplusplus.com/doc/tutorial/inheritance/), but it doesn't > have > > one. > > > > example3b.cpp:41:25: error: no matching function for call to > > ‘libMesh::AnalyticFunction<double>::AnalyticFunction()’ > > > > So, then how do you do what you propose? > > I think you want to write a forwarding constructor for your class that > takes a pointer-to-function and constructs the parent by passing it > along: > > class AnalyticFunctionTest : public AnalyticFunction<Number>{ > public: > AnalyticFunctionTest(void fptr(DenseVector<Output>& output, > const Point& p, > const Real time)) > : AnalyticFunction(fptr) // <-- construct the parent > { > _initialized = true; > } > > > -- > John > -- Andrew E. Slaughter, PhD [email protected] Materials Process Design and Control Laboratory Sibley School of Mechanical and Aerospace Engineering 169 Frank H. T. Rhodes Hall Cornell University Ithaca, NY 14853-3801 (607) 229-1829 http://aeslaughter.github.com/ ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Libmesh-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libmesh-users
