This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

little bug


compiler version : egcs-1.1.2  (pgcc)
system                :  Pentium III - 550Mhz running linux Mandrake 6.0

compiler options :  none
files                     :  attached are 6 short source and header
files that will generate the error.
                                (just g++ main.cc AC.cc CC.cc)

In short, the following compiles

ConcreteClass                                      x;
Handle<AbstractClass>                      y(x);
vector<Handle<AbstractClass> >     z(10,y);

but the next two don't

Handle<AbstractClass>                       x(ConcreteClass());
vector<Handle<AbstractClass> >       y(10,x);

or

vector<Handle<AbstractClass> >       x(10, Handle<AbstractClass>
(ConcreteClass()));



#ifndef AbstractCell_h
#define AbstractCell_h

#include<iostream>

using namespace std;

class AbstractCell {
  
 private:
  bool    alive;
  int     counts;
    
 protected:

  AbstractCell& operator = (const AbstractCell&);

 public:

   AbstractCell(const AbstractCell& o) : alive(o.alive), counts(o.counts) {}

   virtual ~AbstractCell () = 0;
   AbstractCell () : alive(false), counts(0) {}

   virtual AbstractCell* clone () const = 0;
};

#endif

// ConwayCell.h
#ifndef ConwayCell_h
#define ConwayCell_h

#include<iostream>
#include "AC.h"
using namespace std;

class ConwayCell : public AbstractCell {

 private:

 public:
	
   // Using default destructor, copy constructor
   // and assignment operator.
   // ~ConwayCell();
   // ConwayCell (ConwayCell&);
   // ConwayCell& operator = (const ConwayCell&);

  ConwayCell() : AbstractCell() {}   

  virtual ConwayCell* clone () const;
   
};

#endif
#ifndef CellHandle_h
#define CellHandle_h
#include<cassert>
using namespace std;

template <class T>
class CellHandle {

  private:
  	T*         p;

  public:
  	CellHandle() : p(0) {}
  	CellHandle(const T& o) : p(o.clone()) {}
  	CellHandle(const CellHandle& o) : p((!o.p) ? 0 : o.p->clone()) {}
  	
  	~CellHandle() {delete p;}
  	
  	CellHandle& operator = (const CellHandle& rhs) {
          if (this != &rhs) {
            delete p;
            if (!rhs.p)
              p = 0;
            else
              p = rhs.p->clone();}
        return *this;}

    T& operator * () {assert (p); return *p;}
    T* operator -> () {assert (p); return p;}
    const T* operator -> () const {assert (p); return p;}
    bool operator ! () const {return !p;}
    operator bool () const {return !!p;}

};

#endif
#include <iostream>
#include "CH.h"
#include "AC.h"
#include "CC.h"
#include <vector>
using namespace std;

int
main () {
  ConwayCell      x;                     
  CellHandle<AbstractCell> y(x);
  vector <CellHandle<AbstractCell> > z(10, y);    // This compiles

  CellHandle<AbstractCell> xx(ConwayCell());
  vector <CellHandle<AbstractCell> > yy(10, xx);    // This doesn't

}
#include <iostream>
#include "AC.h"
using namespace std;

AbstractCell& AbstractCell::operator = (const AbstractCell& rhs) {
  alive = rhs.alive;
  counts = rhs.counts;
  return *this;}

AbstractCell::~AbstractCell () {}







#include <iostream>
#include "CC.h"
using namespace std;

ConwayCell* ConwayCell::clone () const {
  return new ConwayCell(*this);}


   


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]