<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 &quot;friend&quot; in the sense that it can access members through an explicit pointer.</p>

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