And I am getting errors like this:
./../../C++/ParserClassesBoost/TrackGraph.cc: In function `Parsers::TrackGraph::Transform2D* operator*(const Parsers::TrackGraph::Transform2D&, const Parsers::TrackGraph::Transform2D&)':
./../../C++/ParserClassesBoost/TrackGraph.h:747: error: `float Parsers::TrackGraph::Transform2D::matrix[3][3]' is private
./../../C++/ParserClassesBoost/TrackGraph.cc:675: error: within this context
./../../C++/ParserClassesBoost/TrackGraph.h:747: error: `float Parsers::TrackGraph::Transform2D::matrix[3][3]' is private
./../../C++/ParserClassesBoost/TrackGraph.cc:675: error: within this context
./../../C++/ParserClassesBoost/TrackGraph.h:747: error: `float Parsers::TrackGraph::Transform2D::matrix[3][3]' is private
./../../C++/ParserClassesBoost/TrackGraph.cc:676: error: within this context
make[1]: *** [libMRRParserClassesBoost_la-TrackGraph.lo] Error 1
make[1]: Leaving directory `/home/heller/Deepwoods/ModelRRSystem/Linux/C++/ParserClassesBoost'
make: *** [all] Error 2
Here is the relevant fragment of TrackGraph.cc:
using namespace Parsers;
TrackGraph::Transform2D* operator * (const TrackGraph::Transform2D& t1, const TrackGraph::Transform2D& t2)
{
TrackGraph::Transform2D *new_t = new TrackGraph::Transform2D;
for(int i=0; i < 3; i++)
for(int j=0; j < 3; j++) {
float sum = 0.0;
for(int k=0; k < 3; k++)
sum += t1.matrix[j][k] * t2.matrix[k][i];
new_t->matrix[j][i] = sum;
}
return new_t;
}
And of TrackGraph.h:
namespace Parsers {
class TrackGraph {
public:
class Transform2D {
private:
/** Transform matrix.
*/
float matrix[3][3];
/** Fuzz factor.
*/
const static float FUZZ = .00001;
public:
/** Matrix multiplication.
*/
friend Transform2D* operator * (const Transform2D& t1,const Transform2D& t2);
};
};
};
I don't understand these error messages. They didn't happen before I
added the namespace code. I would *like* to embed my code in a
namespace and not put random stuff into the global namespace, but
either gcc 3.4.6 does not handle namespaces well when dealing with
friend operators or I am doing something wrong, but I don't know what
that could be. For various reasons I don't want to install a newer
version of gcc (I want to stay binary compatible with the rest of my
system).
--
Robert Heller -- 978-544-6933
Deepwoods Software -- Download the Model Railroad System
http://www.deepsoft.com/ -- Binaries for Linux and MS-Windows
hel...@deepsoft.com -- http://www.deepsoft.com/ModelRailroadSystem/
> Here is the relevant fragment of TrackGraph.cc:
Too hard to parse (for me anyway).
Please reduce to the minimal amount of code that allows your audience
to see what you are seeing.
> ./../../C++/ParserClassesBoost/TrackGraph.h:747: error: `float Parsers::TrackGraph::Transform2D::matrix[3][3]' is private
> ./../../C++/ParserClassesBoost/TrackGraph.cc:675: error: within this context
> ...
> I don't understand these error messages.
Variable matrix is private for Transform2D, but you try to access it
from TrackGraph class.
>
> On 17 =D0=BD=D0=BE=D1=8F, 23:56, Robert Heller <hel...@deepsoft.com> wrote:
>
> > ./../../C++/ParserClassesBoost/TrackGraph.h:747: error: `float Parsers::T=
> rackGraph::Transform2D::matrix[3][3]' is private
> > ./../../C++/ParserClassesBoost/TrackGraph.cc:675: error: within this cont=
> ext
> > ...
> > I don't understand these error messages. =C2=A0
>
> Variable matrix is private for Transform2D, but you try to access it
> from TrackGraph class.
No, I am not! Variable matrix is private for Transform2D and is accessed
by *friend* operator * (friend of Transform2D). This code compiles just
fine *without* the namespace declarations, but fails to compile with the
namespace declarations.
OK, I figured out that I needed to qualify the friend operators with the
namespace -- appearently things are ambigious otherwise. The error
message is a little confusing (to me).