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

**URL:** <https://discuss.avogadro.cc/t/trying-to-add-a-new-drawcone-function-and-i-cant-even-add-the-function/780>\
**Category:** Development\
**Created:** [December 6, 2007, 10:50pm UTC](https://discuss.avogadro.cc/t/trying-to-add-a-new-drawcone-function-and-i-cant-even-add-the-function/780 "2007-12-06T22:50:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhanwell](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/mhanwell/32/16_2.png) [@mhanwell](https://discuss.avogadro.cc/u/mhanwell)\
**Post date:** [December 6, 2007, 10:50pm UTC](https://discuss.avogadro.cc/t/trying-to-add-a-new-drawcone-function-and-i-cant-even-add-the-function/780/1 "2007-12-06T22:50:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tim\_Vandermeersch](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/tim_vandermeersch/32/3479_2.png) [@Tim\_Vandermeersch](https://discuss.avogadro.cc/u/Tim_Vandermeersch)\
**Post date:** [December 6, 2007, 11:05pm UTC](https://discuss.avogadro.cc/t/trying-to-add-a-new-drawcone-function-and-i-cant-even-add-the-function/780/2 "2007-12-06T23:05:23Z")

</div>

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](mailto: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](http://SF.Net) email is sponsored by:  
> Check out the new [SourceForge.net](http://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](http://sourceforge.net/services/buy/index.php)
> 
> * * *
> 
> Avogadro-devel mailing list  
> [Avogadro-devel@lists.sourceforge.net](mailto:Avogadro-devel@lists.sourceforge.net)  
> [avogadro-devel List Signup and Options](https://lists.sourceforge.net/lists/listinfo/avogadro-devel)

---

<div class="post-metadata">

**Author:** ![Donald\_Ephraim\_Curti](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/donald_ephraim_curti/32/280_2.png) [@Donald\_Ephraim\_Curti](https://discuss.avogadro.cc/u/Donald_Ephraim_Curti)\
**Post date:** [December 6, 2007, 11:08pm UTC](https://discuss.avogadro.cc/t/trying-to-add-a-new-drawcone-function-and-i-cant-even-add-the-function/780/3 "2007-12-06T23:08:12Z")

</div>

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](mailto: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](http://SF.Net) email is sponsored by:  
> Check out the new [SourceForge.net](http://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](http://sourceforge.net/services/buy/index.php)
> 
> * * *
> 
> Avogadro-devel mailing list  
> [Avogadro-devel@lists.sourceforge.net](mailto:Avogadro-devel@lists.sourceforge.net)  
> [avogadro-devel List Signup and Options](https://lists.sourceforge.net/lists/listinfo/avogadro-devel)

---

<div class="post-metadata">

**Author:** ![mhanwell](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/mhanwell/32/16_2.png) [@mhanwell](https://discuss.avogadro.cc/u/mhanwell)\
**Post date:** [December 7, 2007, 1:02am UTC](https://discuss.avogadro.cc/t/trying-to-add-a-new-drawcone-function-and-i-cant-even-add-the-function/780/4 "2007-12-07T01:02:39Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Tim\_Vandermeersch](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/tim_vandermeersch/32/3479_2.png) [@Tim\_Vandermeersch](https://discuss.avogadro.cc/u/Tim_Vandermeersch)\
**Post date:** [December 7, 2007, 1:25am UTC](https://discuss.avogadro.cc/t/trying-to-add-a-new-drawcone-function-and-i-cant-even-add-the-function/780/5 "2007-12-07T01:25:04Z")

</div>

“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](mailto: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](http://SF.Net) email is sponsored by:  
> Check out the new [SourceForge.net](http://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](http://sourceforge.net/services/buy/index.php)
> 
> * * *
> 
> Avogadro-devel mailing list  
> [Avogadro-devel@lists.sourceforge.net](mailto:Avogadro-devel@lists.sourceforge.net)  
> [avogadro-devel List Signup and Options](https://lists.sourceforge.net/lists/listinfo/avogadro-devel)

---

<div class="post-metadata">

**Author:** ![mhanwell](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/mhanwell/32/16_2.png) [@mhanwell](https://discuss.avogadro.cc/u/mhanwell)\
**Post date:** [December 7, 2007, 1:36am UTC](https://discuss.avogadro.cc/t/trying-to-add-a-new-drawcone-function-and-i-cant-even-add-the-function/780/6 "2007-12-07T01:36:06Z")

</div>

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…
