<p>You should understand what it means to he a static member function of a class. There is no object, you can only access static members which are just namespaced globals. But the method is like a "friend" in the sense that it can access members through an explicit pointer.</p>
<div class="gmail_quote">On Sep 30, 2011 11:22 AM, "Dominik Szczerba" <<a href="mailto:dominik@itis.ethz.ch">dominik@itis.ethz.ch</a>> wrote:<br type="attribution">> It does not seem to work, unless I just miss some C/C++ idiom.<br>
> I was wrong, StiffnessMatrixMultiplication can not be static member,<br>> else all the other non-static members are inaccessible.<br>> So I am trying non-static, but can not pray PCShellSetApply work with<br>> such a function, always get some syntax error.<br>
> <br>> Any hints are highly appreciated.<br>> <br>> Dominik<br>> <br>> <br>> <br>> On Fri, Sep 30, 2011 at 5:54 PM, Dominik Szczerba <<a href="mailto:dominik@itis.ethz.ch">dominik@itis.ethz.ch</a>> wrote:<br>
>> Yes, I only have one instance of my solver class, if this is what you<br>>> mean by a singleton.<br>>> I did not mean to cast my context, I meant to avoid any contexts and<br>>> just access the members. I so far use the context only to pass KSP,<br>
>> Mat and Vec objects around a few functions. I am asking, because I<br>>> have not seen anyone doing it, while it appears natural to me. Also, I<br>>> am doubting if #define __FUNCT__ "StiffnessMatrixMultiplication" will<br>
>> continue to work for static functions.<br>>><br>>> Thanks,<br>>> Dominik<br>>><br>>> On Fri, Sep 30, 2011 at 4:44 PM, Jed Brown <<a href="mailto:jedbrown@mcs.anl.gov">jedbrown@mcs.anl.gov</a>> wrote:<br>
>>> On Fri, Sep 30, 2011 at 09:34, Dominik Szczerba <<a href="mailto:dominik@itis.ethz.ch">dominik@itis.ethz.ch</a>><br>>>> wrote:<br>>>>><br>>>>> I am currently declaring functions outside my C++ solver class to be<br>
>>>> used by via MatShellSetOperation like:<br>>>>><br>>>>> #undef __FUNCT__<br>>>>> #define __FUNCT__ "StiffnessMatrixMultiplication"<br>>>>> PetscErrorCode StiffnessMatrixMultiplication(Mat A, Vec x, Vec y)<br>
>>>> {<br>>>>> // ...<br>>>>> ierr = MatShellGetContext(A, (void**) &ctx);CHKERRQ(ierr);<br>>>>> Mat foo;<br>>>>> foo = ctx->foo;<br>
>>>> // ...<br>>>>> }<br>>>>><br>>>>> and I set/get contexts to e.g. pass 'foo' around. Is it possible in<br>>>>> Petsc / is it a good idea / to instead declare such functions as<br>
>>>> static class member functions and then use the class members directly<br>>>>> without any contexts shuffled around?<br>>>><br>>>> You have to go through the context unless your class is a singleton. Or do<br>
>>> you still mean casting the ctx to your class type and accessing members<br>>>> through it (explicit "this")? That should work, if you prefer.<br>>><br></div>