From e226392213974a446d85c5cf61125d2be654f765 Mon Sep 17 00:00:00 2001 From: deal Date: Mon, 16 Dec 2002 17:59:24 +0000 Subject: [PATCH] Add some more this->. Document why. git-svn-id: https://svn.dealii.org/trunk@6825 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/examples/step-7/step-7.cc | 50 +++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/deal.II/examples/step-7/step-7.cc b/deal.II/examples/step-7/step-7.cc index cf6cc13131..e25e070aab 100644 --- a/deal.II/examples/step-7/step-7.cc +++ b/deal.II/examples/step-7/step-7.cc @@ -224,12 +224,33 @@ class Solution : public Function, // their mathematical definition and // probably needs not much // explanation. + // + // The only thing that is worth + // mentioning is that if we access + // elements of a base class that is + // template dependent (in this case + // the elements of + // ``SolutionBase''), then the + // C++ language forces us to write + // ``this->n_source_centers'' (for + // example). Note that the ``this->'' + // qualification is not necessary if + // the base class is not template + // dependent, and also that the gcc + // compilers, among others, don't + // enforce this requirement of the + // C++ standard. The reason why this + // is necessary is complicated; some + // books on C++ may explain it, so if + // you are interested you can look it + // up under the phrase ``two-stage + // (name) lookup''. template double Solution::value (const Point &p, const unsigned int) const { double return_value = 0; - for (unsigned int i=0; in_source_centers; ++i) { // One of the few things worth // mentioning is the following @@ -237,13 +258,14 @@ double Solution::value (const Point &p, // the vector (x-x_i). It is // computed in the way that one // would intuitively expect: - const Point shifted_point = p-source_centers[i]; + const Point shifted_point = p-this->source_centers[i]; // The ``Point'' class // offers a member function // ``square'' that does what // it's name suggests. - return_value += std::exp(-shifted_point.square() / (width*width)); + return_value += std::exp(-shifted_point.square() / + (this->width * this->width)); }; return return_value; @@ -279,9 +301,9 @@ Tensor<1,dim> Solution::gradient (const Point &p, // class, which makes up for their // mutual exchange ability. - for (unsigned int i=0; in_source_centers; ++i) { - const Point shifted_point = p-source_centers[i]; + const Point shifted_point = p-this->source_centers[i]; // For the gradient, note that // it's direction is along @@ -290,7 +312,8 @@ Tensor<1,dim> Solution::gradient (const Point &p, // vector, where the factor is // given by the exponentials. return_value += (-2 / (width*width) * - std::exp(-shifted_point.square() / (width*width)) * + std::exp(-shifted_point.square() / + (this->width * this->width)) * shifted_point); }; @@ -331,18 +354,21 @@ double RightHandSide::value (const Point &p, const unsigned int) const { double return_value = 0; - for (unsigned int i=0; in_source_centers; ++i) { - const Point shifted_point = p-source_centers[i]; + const Point shifted_point = p-this->source_centers[i]; // The first contribution is // the Laplacian: - return_value += ((2*dim - 4*shifted_point.square()/(width*width)) / - (width*width) * - std::exp(-shifted_point.square() / (width*width))); + return_value += ((2*dim - 4*shifted_point.square()/ + (this->width * this->width)) / + (this->width * this->width) * + std::exp(-shifted_point.square() / + (this->width * this->width))); // And the second is the // solution itself: - return_value += std::exp(-shifted_point.square() / (width*width)); + return_value += std::exp(-shifted_point.square() / + (this->width * this->width)); }; return return_value; -- 2.39.5