help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Confused about friend operators, namespaces, and private members...


From: Robert Heller
Subject: Confused about friend operators, namespaces, and private members...
Date: Tue, 17 Nov 2009 15:56:08 -0600

I am using gcc 3.4.6 under CentOS 4.8 (RHEL 4.8):
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-java-awt=gtk
--host=i386-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-11)

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
address@hidden       -- http://www.deepsoft.com/ModelRailroadSystem/
                                                                                
                              


reply via email to

[Prev in Thread] Current Thread [Next in Thread]