Trying to add a new drawCone function and I can't even add the function

Hi,

This is possibly something I am doing wrong and just not spotting it.
All I am doing is adding a new pure virtual function in the base
Painter class and then implementing it in the painters. Right now they
are empty. The first attempt the GLPainter version had some code.

I get the following compile error every time,

/Users/mhanwell/devel/avogadro-git/libavogadro/src/glwidget.cpp: In
member function ‘void Avogadro::GLWidget::constructor(const
Avogadro::GLWidget*)’:
/Users/mhanwell/devel/avogadro-git/libavogadro/src/glwidget.cpp:423:
error: cannot allocate an object of abstract type ‘Avogadro::GLPainter’
/usr/local/include/avogadro/glpainter.h:50: note: because the
following virtual functions are pure within ‘Avogadro::GLPainter’:
/Users/mhanwell/devel/avogadro-git/libavogadro/include/avogadro/…/…/
src/painter.h:132: note: virtual void
Avogadro::Painter::drawCone(const Eigen::Vector3d&, const
Eigen::Vector3d&, double)

The diff for the minimal commit is included below. I would really
appreciate someone letting me know what I am missing. Geoff took a
look but couldn’t spot it but the definition is basically identical to
drawLine…

Any ideas?

Thanks,

Marcus

diff --git a/libavogadro/src/glpainter.h b/libavogadro/src/glpainter.h
index 0e0cb74…c4b7a56 100644
— a/libavogadro/src/glpainter.h
+++ b/libavogadro/src/glpainter.h
@@ -146,6 +146,9 @@ namespace Avogadro
void drawMultiCylinder (const Eigen::Vector3d &end1, const
Eigen::Vector3
double radius, int order, double shift);

  •  void drawCone(const Eigen::Vector3d &p1, const Eigen::Vector3d  
    

&p2,

  •                double radius) { }
    
  •  /**
      * Draws a GL line between the given points of the given width.
      * @param start the position of the start of the line.
    

diff --git a/libavogadro/src/painter.h b/libavogadro/src/painter.h
index d679287…4f88ad5 100644
— a/libavogadro/src/painter.h
+++ b/libavogadro/src/painter.h
@@ -128,6 +128,9 @@ namespace Avogadro
virtual void drawMultiCylinder (const Eigen::Vector3d &end1,
const Eigen:
double radius, int order, double
shift) = 0;

  •  virtual void drawCone(const Eigen::Vector3d &p1, const  
    

Eigen::Vector3d &p

  •                        double radius) = 0;
    
  •  /**
      * Draws a line between the given points of the given width.
      * @param start the position of the start of the line.
    

diff --git a/libavogadro/src/povpainter.h b/libavogadro/src/povpainter.h
index 06c37a5…beb4083 100644
— a/libavogadro/src/povpainter.h
+++ b/libavogadro/src/povpainter.h
@@ -141,6 +141,9 @@ namespace Avogadro
void drawMultiCylinder (const Vector3d &end1, const Vector3d &end2,
double radius, int order, double shift);

  • void drawCone(const Eigen::Vector3d &, const Eigen::Vector3d &,
  •              double) { }
    
  • /**
    * Draws a line between the given points of the given width.
    * @param start the position of the start of the line.

If you remove the “= 0” from the virtual function declaration, and
define it as {} , it works… Not sure why it works for other
functions and not this one??

Tim

On Dec 6, 2007 11:50 PM, Marcus D. Hanwell mhanwell@gmail.com wrote:

Hi,

This is possibly something I am doing wrong and just not spotting it.
All I am doing is adding a new pure virtual function in the base
Painter class and then implementing it in the painters. Right now they
are empty. The first attempt the GLPainter version had some code.

I get the following compile error every time,

/Users/mhanwell/devel/avogadro-git/libavogadro/src/glwidget.cpp: In
member function ‘void Avogadro::GLWidget::constructor(const
Avogadro::GLWidget*)’:
/Users/mhanwell/devel/avogadro-git/libavogadro/src/glwidget.cpp:423:
error: cannot allocate an object of abstract type ‘Avogadro::GLPainter’
/usr/local/include/avogadro/glpainter.h:50: note: because the
following virtual functions are pure within ‘Avogadro::GLPainter’:
/Users/mhanwell/devel/avogadro-git/libavogadro/include/avogadro/…/…/
src/painter.h:132: note: virtual void
Avogadro::Painter::drawCone(const Eigen::Vector3d&, const
Eigen::Vector3d&, double)

The diff for the minimal commit is included below. I would really
appreciate someone letting me know what I am missing. Geoff took a
look but couldn’t spot it but the definition is basically identical to
drawLine…

Any ideas?

Thanks,

Marcus

diff --git a/libavogadro/src/glpainter.h b/libavogadro/src/glpainter.h
index 0e0cb74…c4b7a56 100644
— a/libavogadro/src/glpainter.h
+++ b/libavogadro/src/glpainter.h
@@ -146,6 +146,9 @@ namespace Avogadro
void drawMultiCylinder (const Eigen::Vector3d &end1, const
Eigen::Vector3
double radius, int order, double shift);

  •  void drawCone(const Eigen::Vector3d &p1, const Eigen::Vector3d
    

&p2,

  •                double radius) { }
    
  • /**
     * Draws a GL line between the given points of the given width.
     * @param start the position of the start of the line.
    

diff --git a/libavogadro/src/painter.h b/libavogadro/src/painter.h
index d679287…4f88ad5 100644
— a/libavogadro/src/painter.h
+++ b/libavogadro/src/painter.h
@@ -128,6 +128,9 @@ namespace Avogadro
virtual void drawMultiCylinder (const Eigen::Vector3d &end1,
const Eigen:
double radius, int order, double
shift) = 0;

  •  virtual void drawCone(const Eigen::Vector3d &p1, const
    

Eigen::Vector3d &p

  •                        double radius) = 0;
    
  • /**
     * Draws a line between the given points of the given width.
     * @param start the position of the start of the line.
    

diff --git a/libavogadro/src/povpainter.h b/libavogadro/src/povpainter.h
index 06c37a5…beb4083 100644
— a/libavogadro/src/povpainter.h
+++ b/libavogadro/src/povpainter.h
@@ -141,6 +141,9 @@ namespace Avogadro
void drawMultiCylinder (const Vector3d &end1, const Vector3d &end2,
double radius, int order, double shift);

  • void drawCone(const Eigen::Vector3d &, const Eigen::Vector3d &,
  •              double) { }
    
  • /**
    • Draws a line between the given points of the given width.
    • @param start the position of the start of the line.

SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It’s the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php


Avogadro-devel mailing list
Avogadro-devel@lists.sourceforge.net
avogadro-devel List Signup and Options

In the GLPainter::drawCone function try putting something other than
just {}.

Put: int x = 0; or something like that. I think that it’s recognizing
{} as 0 in your subclass and thus it thinks you haven’t re-implemented
it. Possibly the compiler is optimizing {} out.


Donald

(Thu, Dec 06, 2007 at 05:50:15PM -0500) “Marcus D.Hanwell” mhanwell@gmail.com:

Hi,

This is possibly something I am doing wrong and just not spotting it.
All I am doing is adding a new pure virtual function in the base
Painter class and then implementing it in the painters. Right now they
are empty. The first attempt the GLPainter version had some code.

I get the following compile error every time,

/Users/mhanwell/devel/avogadro-git/libavogadro/src/glwidget.cpp: In
member function ?void Avogadro::GLWidget::constructor(const
Avogadro::GLWidget*)?:
/Users/mhanwell/devel/avogadro-git/libavogadro/src/glwidget.cpp:423:
error: cannot allocate an object of abstract type ?Avogadro::GLPainter?
/usr/local/include/avogadro/glpainter.h:50: note: because the
following virtual functions are pure within ?Avogadro::GLPainter?:
/Users/mhanwell/devel/avogadro-git/libavogadro/include/avogadro/…/…/
src/painter.h:132: note: virtual void
Avogadro::Painter::drawCone(const Eigen::Vector3d&, const
Eigen::Vector3d&, double)

The diff for the minimal commit is included below. I would really
appreciate someone letting me know what I am missing. Geoff took a
look but couldn’t spot it but the definition is basically identical to
drawLine…

Any ideas?

Thanks,

Marcus

diff --git a/libavogadro/src/glpainter.h b/libavogadro/src/glpainter.h
index 0e0cb74…c4b7a56 100644
— a/libavogadro/src/glpainter.h
+++ b/libavogadro/src/glpainter.h
@@ -146,6 +146,9 @@ namespace Avogadro
void drawMultiCylinder (const Eigen::Vector3d &end1, const
Eigen::Vector3
double radius, int order, double shift);

  •  void drawCone(const Eigen::Vector3d &p1, const Eigen::Vector3d
    

&p2,

  •                double radius) { }
    
  •  /**
      * Draws a GL line between the given points of the given width.
      * @param start the position of the start of the line.
    

diff --git a/libavogadro/src/painter.h b/libavogadro/src/painter.h
index d679287…4f88ad5 100644
— a/libavogadro/src/painter.h
+++ b/libavogadro/src/painter.h
@@ -128,6 +128,9 @@ namespace Avogadro
virtual void drawMultiCylinder (const Eigen::Vector3d &end1,
const Eigen:
double radius, int order, double
shift) = 0;

  •  virtual void drawCone(const Eigen::Vector3d &p1, const
    

Eigen::Vector3d &p

  •                        double radius) = 0;
    
  •  /**
      * Draws a line between the given points of the given width.
      * @param start the position of the start of the line.
    

diff --git a/libavogadro/src/povpainter.h b/libavogadro/src/povpainter.h
index 06c37a5…beb4083 100644
— a/libavogadro/src/povpainter.h
+++ b/libavogadro/src/povpainter.h
@@ -141,6 +141,9 @@ namespace Avogadro
void drawMultiCylinder (const Vector3d &end1, const Vector3d &end2,
double radius, int order, double shift);

  • void drawCone(const Eigen::Vector3d &, const Eigen::Vector3d &,
  •              double) { }
    
  • /**
    * Draws a line between the given points of the given width.
    * @param start the position of the start of the line.

SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It’s the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php


Avogadro-devel mailing list
Avogadro-devel@lists.sourceforge.net
avogadro-devel List Signup and Options

Donald Ephraim Curtis wrote:

In the GLPainter::drawCone function try putting something other than
just {}.

Put: int x = 0; or something like that. I think that it’s recognizing
{} as 0 in your subclass and thus it thinks you haven’t re-implemented
it. Possibly the compiler is optimizing {} out.

I tried that and it still doesn’t compile. Not sure what the problem is.
Originally I was doing calculations and everything. Also { } is working
for other functions…

“virtual void drawCone(const Eigen::Vector3d &p1, const
Eigen::Vector3d &p2, double radius) {}” instead of “virtual void
drawCone(const Eigen::Vector3d &p1, const Eigen::Vector3d &p2, double
radius) = 0;” works here…

On Dec 7, 2007 2:02 AM, Marcus D. Hanwell mhanwell@gmail.com wrote:

Donald Ephraim Curtis wrote:

In the GLPainter::drawCone function try putting something other than
just {}.

Put: int x = 0; or something like that. I think that it’s recognizing
{} as 0 in your subclass and thus it thinks you haven’t re-implemented
it. Possibly the compiler is optimizing {} out.

I tried that and it still doesn’t compile. Not sure what the problem is.
Originally I was doing calculations and everything. Also { } is working
for other functions…


SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It’s the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php


Avogadro-devel mailing list
Avogadro-devel@lists.sourceforge.net
avogadro-devel List Signup and Options

Tim Vandermeersch wrote:

“virtual void drawCone(const Eigen::Vector3d &p1, const
Eigen::Vector3d &p2, double radius) {}” instead of “virtual void
drawCone(const Eigen::Vector3d &p1, const Eigen::Vector3d &p2, double
radius) = 0;” works here…

Yeah I figured that would work but I don’t get why what I have done does
not work. I want it to be a pure virtual function that must be
implemented in the derived classes. The other functions in that class
are defined in this way and that works so why on earth doesn’t it work
now? The other stuff I added worked fine too so this just doesn’t make
sense to me.

I will try adding it again now I am home - it must be something strange
I am doing…