[vtkusers] linking problem while extending VTK

David Cole david.cole at kitware.com
Wed May 11 08:52:11 EDT 2005


It looks like this is the linker's way of telling you "don't call 
virtual methods from a constructor"...

You should move the code from your constructor into some sort of 
initialize method that is always called after the constructor is done. 
In general, the behavior you get when you call a virtual method from a 
constructor is undefined because some of the constructors from your 
inheritance chain have not yet been called. Therefore you should avoid 
making such calls until after all the constructors are completely 
done... I've always been curious why compilers even let you make virtual 
method calls from constructors. Seems to me like it would save a lot of 
people a lot of time just to make code like this result in a compiler 
error with a "can't make virtual method call from a constructor" error 
message.


Hope this helps,
David


francesco caruso wrote:

> Hello VTK USERS
>
> I'm trying to extend VTK creating a new class
> called vtkARWindow, that own two overlapped renderers.
>
> when i try to compile I get this error:
>
> vtkARWindow.o(.text+0x69): In function 
> `vtkARWindow::vtkARWindow[not-in-charge]()':
> : undefined reference to `vtable for vtkARWindow'
> vtkARWindow.o(.text+0x159): In function 
> `vtkARWindow::vtkARWindow[in-charge]()':
> : undefined reference to `vtable for vtkARWindow'
> collect2: ld returned 1 exit status
>
> If I used objectfactory instead of normal constructor
> I shouldn't obtain this error?
>
> Any kind of help will be appreciated!!!
>
> I hope you don't mind if I attach some line of code...
>
> //vtkARWindow.h
> #ifndef VTK_AR_WINDOW
> #define VTK_AR_WINDOW
>
> #include "vtkXOpenGLRenderWindow.h"
> #include "vtkRenderer.h"
> #include "vtkARImageRenderer.h"
>
> class vtkARImageRenderer;
>
> class vtkARWindow : public vtkXOpenGLRenderWindow {
>     public: //VARS
>         vtkRenderer* ImageRenderer;
>         vtkRenderer* VirtObjRenderer;
>     //public: //METHODS
>         static vtkARWindow* New() { return new vtkARWindow;};
>         vtkARWindow();
>         ~vtkARWindow();
> //        void SetImageRenderer(vtkARImageRenderer* ren);
> //        void SetVirtObjRenderer(vtkRenderer* ren);
>         void SetImage(unsigned char* image);
>        
>         //void vtkARWindow(const vtkARWindow &w);//not //implemented
> };
> #endif
>
> //file vtkARWindow.cxx
> vtkARWindow::vtkARWindow(){
>     this->ImageRenderer = vtkRenderer::New();
>     this->VirtObjRenderer = vtkRenderer::New();
>     this->SetNumberOfLayers(2);
>     this->AddRenderer(ImageRenderer);
>     this->AddRenderer(VirtObjRenderer);
>     ImageRenderer->SetLayer(0);
>     VirtObjRenderer->SetLayer(1);
>     this->SetSize(WinXsize, WinYsize);
> }
>
> thanks in advance
> _______________________________________________
> This is the private VTK discussion list. Please keep messages 
> on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



More information about the vtkusers mailing list