[solved] Template virtual function in C++

I know this isn't legal C++ due to the compiler not being able to determine how big exactly the vtable is. I'm looking for alternatives.
Basically, I have an abstract base class defining the interface for a set of derived classes. One of the functions being exposed through this interface is called run(). Each derived class does something different with run(). So it looks something like this:-
class base {
protected:
base() { }
public:
virtual void run(...) = 0;
/* rest of api here */
class derived : public base {
private:
template<class T>
void runTemplate() {
/* Do something with data-type T */
public:
void run(...) {
switch(some_int_value_from_the_input) {
case 1:
runTemplate<char>();
break;
case 2:
runTemplate<short>();
break;
case 3:
runTemplate<int>();
break;
default:
/* throw error */
My 'problem' is that every single derived class has exactly the same run() function, they only differ in the algorithm within runTemplate(). However, since I'm not allowed to implement run() in base calling a templated virtual function in base, I seem forced to have the code above, which seems to me to unnecessarily duplicate code.
Is there another way to implement the above? My objective is to keep the amount of coding done in the derived class to the bare minimum (pretty much just the algorithm if possible), hence why I'm trying to move run()'s definition from derived to base.
Last edited by ngoonee (2009-10-07 14:11:01)

scio wrote:
Sorry I typing to you and talking to someone else... I meant polymorphism.
However, I'm not sure if I understand your end goal.  It seems like templates are not needed, but there might be a reason in your code:
class base {
protected:
base() { }
public:
virtual void run(...) = 0;
/* rest of api here */
class algowrapper{
public:
algowrapper(...) {
/* Use arg to setup algorithm /*
static void processInput(...) {
/* Do something with input and defined algorithm */
class runner : public base{
protected:
runner():algo(NULL) { }
algowrapper* algo;
public:
virtual void run(...) {
if (algo)
algo->processInput();
class derived : public runner{
public:
derived(...):runner(),algo(new algowrapper(/* some algorithm */)) { }
class derived2 : public runner{
public:
derived(...):runner(),algo(new algowrapper(/* different algorithm */)) { }
Hmmm, looks like my explaining skills leave a lot to be desired. Basically I want the separate algorithms to be fully implemented within the derived classes.
Usage case is that, for example, I distribute my executable which includes the object file for base. One of the things my executable does is load .so files (using dlopen), which will be compiled separately from the main executable. These .so files return a pointer to base, but different .so files implement different algorithms. So I can only access the functions which belong to base, since all I have is a pointer to base and no knowledge of the specific derived class, and i just call base->run(...) which is implemented in each derived class and it should handle the rest.
The problem, as I see it, is that runtemplate() shouldn't need to be part of the API in base, yet if it doesn't exist in base, run() cannot call it. Even if it exists in base, it cannot have the form of a template since this is illegal in C++.

Similar Messages

  • HT203175 I have no problem signing on to iTunes my issue is once on the site I can not use the "search". It says there is a runtime error R6025 pure virtual function call. Has anyone had this problem and how do I fix it. Thanks

    I do not have a problem getting in the iTunes stores. My issue is once on the site I can not use the "search". It says there is a pure virtual function call R6025. How can I solve this problem? Do I have to create a new account? Do I have to uninstall and re-install? Thanks

    Thanks so much for your feedback. I really appreciate any input here.
    If someone from Adobe could GUARANTEE that this problem would go away if I
    purchased CS4, I would pony up the cash and do it. However, I'm skeptical
    about that because I just saw someone else post a message on the forum today
    who is running CS4 and getting the exact same runtime error as me.
    I'll try un-installing and re-installing as Admin, and if that doesn't work,
    maybe I can find a used copy of CS3.
    In the meantime, I'm also wondering if a Photoshop file can carry any sort
    of corrupt metadata inside it once it has errored out? Reason I ask is, I
    had to port all of my old PSD files to the new computer, and I only seem to
    be getting this error when I attempt to work on one of the files that
    previously got the runtime error when they were sitting on my XP machine.
    When I create new files from scratch on this new computer, they seem to be
    working just fine (at least, for now).
    If so, I would probably be smart to never open those troublesome
    "errored-out" files again.

  • URGENT: Bug in Adobe Acrobat X /// Acrobat.exe Runtime Error! R6025 - pure virtual function call

    Hello
    I work usually with large PDF documents, and I was trying to convert a PDF document of 1000 pages ONE THOUSAND PAGES, to little PDF documents of 10 MB each one.
    When I tried to convert the PDF file into little ones, craaashhhhhhhhhhhhhhhhhh
    I got this message:
    Acrobat.exe Runtime Error! R6025 - pure virtual function call - Microsoft Visual C++ Runtime Library
    This seems to be a BUG AS BIG A GRAND PIANO... so I would like someone from Adobe tell me how may I solve this problem or if they will release an update soon?
    Thank you

    This is a user to user forum and we don't post information here (or anywhere else public) about what may or may not be in future patch releases.
    If you have a bug with an Adobe product you must report it using the correct form.

  • Intermittent Runtime error - pure virtual function call

    I have an intermittent runtime error - pure virtual function call & don't know what cause it? Since It only occurs & crashes once awhile therefore it's difficult to trap it for debugging.I suspect it come from TestStand ActiveX API which I use in my User Interface Application project but I'm not really sure.
    Does anyone experience this kind of problem when working with TestStand API ? If so any
    suggestion? I have noticed in the TestStand API header file teapi.tlh contain many raw_.... function defined as pure virtual function. What are these raw_... function ? I don't think I use any of these function in my project.
    Many thanks!

    Danh,
    I don't believe that your problem can be solved with the information you have provided unless someone else has experienced the same symtpoms which coincidentally have the same cause as in your case.
    Is there any other information you can provide that can help localize the problem?
    1) What is happening when the error occurs?
    2) Does the error always occur in the same place?
    3) Does it always occur with use of certain resources (e.g. DAQ, GPIB, VISA, printer)?
    4) Does it occur when using the sequence editor?
    5) Does it occur when using one of the shipping operator interfaces?
    6) Does it occur only when using your operator interfaces?
    7)Is it related to a specific sequence or any sequence?
    8) Does it happen when you executed your sequence with/without a process model entr
    y point (i.e. Execute>>Test UUTs, Execute>>Singal Pass or Execute>>Run MainSequence)?
    9) How often does it happen?
    10) What version of TestStand are you using?
    11) With what language (include versions) are you programming your code modules?
    12) With what language (include versions) are you programming your operator interface?
    13) Is there any error code reported with this error message?
    14) Is this error reported in a TS run-time error dialog or is it reported directly 1by the operating system?
    15) Have you searched the web for related errors? For example, the following link describes a particular programming mistake that can lead to this error
    http://support.microsoft.com/support/kb/articles/Q125/7/49.asp
    By investigating answers to the above questions you may be able to narrow the cause of this error, which might allow you or others to help solve the problem.

  • Photoshop CC r6025 pure virtual function call

    I recently signed up for Creative Cloud and shortly after that I started to recieve the r6025 pure virtual function call error with PS CC crashing. This will happen with both the x86 and x64 versions of PS CC. It does not happen every time, only about 30%-40% of the time. Usually, but not always, a restart of the program solved the problem.I performed an unstall of PS CC but that did not solve my problem. Prior to switching to Creative Cloud I had no problems whatsoever with PS CS6. This issue started after installing CC and updating PS CS6 to Photoshop CC. I do not think this is a hardware or OS problem but FGOS I an running the following:
    OS - Windows 8 Pro x64
    RAM - 16GB DDR3
    Video - NVIDIA GeForce GT 640 with 2048 MB of VRAM
    CPU - Intel Core i7 2600
    Plug-ins - onOne, Nik, Imagenomic, Topaz Labs, Alien Skin, Unified Color and a few others. All of these were installed and running fine before the CC switch.
    Does anyone have any ideas as this has become very frustrating for me.
    Thanks

    Thanks guys. I'll reply to your messages in the above order.
    System Log -
    For all these photoshop.exe is the faulting application both x86 and 64-bit. I havent seperated them out (x86 vs x64) but casn do that if you want. I mostly use the x86 version of Photoshop simply because a couple of my favorite plug=ins don't work in the 64-bit version.
    Faulting modules -
    unknown - 2 times
    MSVCR100.dll - 9 times
    KERNELBASE.dll - 3 times
    MultiProcessorService.8BX_unloaded - 1 time
    CreativeCloud.exe showed up once as the faulting application and the faulting module was VulcanWrapper.exe.
    FGFOS the above are a mix of Photoshop CS6 and Photoshop CC. That came about because I was running PS CS6 when I signed up for Creative Cloud and my version of CS6 was upgraded to the Extended version. About a week ago I uninstalled then reinstalled Photoshop and this time the version was Photoshop CC.
    With regard to the plug-ins I use the vendor's installation program. I have a few others that are just an *.8bf file that I copied to Photoshop's plug-in directory. Most, if not all, of this type of plug-in are my oldest plug-ins and are only used with Photoshop x86. I'll move these from Photoshop's plug-in directory first just because they will be the easiest to work with. If I get a crash while they are gone then I'll remove my other plug-ins.
    Again, thanks guys I do appreciate this. I've never run into this particular issue before so it a good, albeit frustrating, learning process.

  • Runtime Error. R6025 - pure virtual function call. What is that?!

    Hi, would like to know what is wrong with my ipod. Since abt 3 wks ago, my ipod is functioning very slow upon connection to the computer for charging. The iTune is always lagging with it was charging too. But last week, it got worse. My computer does not recognise the hard disk nor the generic volume at all, but was still chargeable. Bu today, when i on my iTunes i was being "chase out" with the Runtime Error: R6025 - pure virtual function call. May i know what is it and how i can solve the problem??? Would really appreciate all the help i can get! Thanks!

    I'm getting this same problem.

  • Pure virtual function call error while saving the vi.

    Hi everybody,
    I'm using LabVIEW 8.6 to create the applications. I got "fatal error: memorymanager.cpp: line 437 and Pure virtual function call error: R6025, while i try to save the vi. Also no DAQ cards are interfaced with my PC.
    How can i rectify this error?
    Solved!
    Go to Solution.

    Hi solutions,
    the simplest solution would be to recreate the VI from scratch. Yes, really!
    You can also try to copy the block diagram to a new VI, this might help too. Or to clean up your VI be creating subVIs…
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Flash cc 2015 (feb 2015) r6025 pure virtual function call

    Upon exiting I get a " r6025 pure virtual function call "
    Flash (process) keeps running and I have to manually kill it before being able to restart it.
    OS: Windows 7

    first reset your preferences:
    reset preferences -
    adobe media encoder: https://forums.adobe.com/thread/1713540
    after effects:  http://helpx.adobe.com/after-effects/using/preferences.html
    dreamweaver:  https://helpx.adobe.com/dreamweaver/kb/restore-preferences-dreamweaver-cs6-cc.html
    flash:  http://helpx.adobe.com/flash/kb/re-create-preferences-flash-professional.html
    illustrator:  http://helpx.adobe.com/illustrator/using/setting-preferences.html
    indesign:  https://forums.adobe.com/thread/526990
    lightroom: https://helpx.adobe.com/lightroom/help/setting-preferences-lightroom.html
    muse (mac): https://forums.adobe.com/thread/1246022?tstart=0
    photoshop:  https://forums.adobe.com/thread/375776
    photoshop elements:  http://www.photokaboom.com/photography/learn/Photoshop_Elements/troubleshooting/1_delete_p references_file.htm
    premiere pro: http://www.mediacollege.com/adobe/premiere/pro/troubleshooter/trash-preferences.html
    if that fails, consider this - How to fix Runtime error R6025? - Solved | Fix Errors
    if that fails, uninstall cc, clean (Use the CC Cleaner Tool to solve installation problems | CC, CS3-CS6) and reinstall.

  • Warning :: Derived class hides the base class virtual function

    We are porting from CC5.3 to CC5.8 compiler with Sun Studio one compiler. After plenty of hurdles we are in the final stage of removing the warning messages... Amoung the plenty the following one is very common and in different files. Why am I getting this error in 5.8 and not in 5.3 compiler....
    Warning: derived_Object::markRead Hides the virtual function base_Object::markRead(ut_SourceCodeLocation&) const in a virtual base
    From this it is easily understandable that the base class mark read was hidden by derived class markRead... when we drive and override the derived class function.... It is all over the place....
    Thank you,
    Saravanan Kannan
    //public: using xx_Object :: markRead;
    virtual void markRead() const;

    The Sun C++ FAQ discusses the warning message:
    http://developers.sun.com/prodtech/cc/documentation/ss11/mr/READMEs/c++_faq.html#Coding1
    Notice that warnings are not necessarily errors. But I applaud your desire to fix the code so that it generates no warnings. I wish more of our customers could be persuaded to do the same. :-)
    C++ 5.3 issues this warning, by the way. Example:
    struct B { virtual int foo(int); };
    struct D : B { virtual int foo(double); }; // line 2
    D d;
    line 2: Warning: D::foo hides the virtual function B::foo(int).
    If for your particular code you do not see a warning with C++ 5.3, it would be due to a bug in C++ 5.3 that was later fixed.

  • When i open my i3tunes on my computer i get an error message telling me that iTunes has stopped working..the message is as follows...Microsoft Visual C  runtime library Program C:\program files (86) iTunes\iTunes.exe  R6025 -Pure virtual function call..

    when i open my i3tunes on my computer i get an error message telling me that iTunes has stopped working..the message is as follows...Microsoft Visual C  runtime library Program C:\program files (86) iTunes\iTunes.exe  R6025 -Pure virtual function call.. How do i fix this

    For general advice see Troubleshooting issues with iTunes for Windows updates.
    The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down page in case one of them applies.
    Your library should be unaffected by these steps but there is backup and recovery advice elsewhere in the user tip.
    tt2

  • ITunes crashes when doing a power search. I get a Microsoft Visual C   Runtime Library Error message: Program C:\Program Files (x86)\iTunes\iTunes.exe R6025.  Pure virtual functional call.  If I select ok, Windows 7 pops up with iTunes has stopped working

    iTunes crashes when doing a power search. I get a Microsoft Visual C   Runtime Library Error message: Program C:\Program Files (x86)\iTunes\iTunes.exe R6025.  Pure virtual functional call.  If I select ok, Windows 7 pops up with iTunes has stopped working and then it shuts iTunes down.  Anyone else every have this issue.  Any ideas on a fix?
    Thanks,

    For general advice see Troubleshooting issues with iTunes for Windows updates.
    The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down page in case one of them applies.
    Your library should be unaffected by these steps but there is backup and recovery advice elsewhere in the user tip.
    tt2

  • "R6025 -pure virtual function call" Error While Use Adobe Media Encoder

    I'm trying to use Adobe Media Encoder (CS3) to output a project to H.264. I have about 3 minutes of footage on the Premier Pro CS3 Timeline, all of it in Cineform AVI intermediate format. When I export the movie through AME and select 2-pass VBR, it gets through the first pass, but crashes at 50% on the second pass with the error:
    "Microsoft Visual C++ Runtime Library
    Runtime Error!
    Program E:\Progra...
    R6025
    -pure virtual function call"
    Any ideas what may be causing this error?

    Point taken...
    I'm on a Dell XPS 720 Windows XP (32-bit) system, with all up-to-date service packs and patches. I have 4GB RAM installed, and Production Premium CS3, TMPGEncXPress and Cineform's Neo Scene. Neo Scene is a recent addition and the problem existed prior to its installation. I have two 7900GS graphics cards (each with 256MB video RAM), running in SLI mode.
    I dual boot Windows XP: One system is "Messy" with all kinds of stuff installed. The other is "Clean" and has virtually nothing installed, except for the three suites previously mentioned. No anti-virus or anti-spyware software is installed on the Clean system. I get the error on both systems.
    I saw the post from September 2007 reference vcredist_x86. I'll be trying that at my next opportunity, however, I'm not sure that will fix it, as I don't see why both systems would suffer from the same corruption. I'll also be swapping out RAM to see if that fixes the issue.

  • Virtual function problem with SC 4.2

    Hi
    I'm using SC CC 4.2
    [CC -V
    CC: WorkShop Compilers 4.2 18 Sep 1997 C++ 4.2 patch 104631-04]
    not the latest patch, I realize.
    The following bit of code:
    ProcessParameters *ppp = &(_config.process_params_);
    ppp->save_to_file(String("abc"));
    config.processparams_.save_to_file(String("xyz"));
    does not work as I'd expect it to!
    config.processparams_ is of type ProcessParametersEnhanced,
    and the definition of this, and its base class, looks like:
    class ProcessParameters
    public:
    virtual int save_to_file(String filename);
    and
    class ProcessParametersEnhanced : public ProcessParameters
    public:
    virtual int save_to_file(String filename);
    (I've cut everything else out of the class definitions for clarity, and I've changed the names a bit as well, hopefully without typos).
    ppp->save_to_file(String("abc"));
    calls ProcessParameters::save_to_file(String)
    even though ppp points to an instance of ProcessParametersEnhanced, and the function is virtual.
    I've tried building a small test application, using the minimum class interfaces, but this works as I'd expect (it also works fine with gcc).
    I'm getting deseperate. Is there a bug in SC4.2 whereby it fails to resolve virtual functions correctly?
    TIA
    Paul Floyd

    Oh well, it was an SC4.2 bug
    Patch-ID# 104631-07
    Keywords: C++ 4.2 SC4.2
    Synopsis: SPARCompiler C++ 4.2: C++ 4.2 patch for Solaris 2.x
    Date: Jul/17/98
    4066271 C++ has a problem with a copy constructor using virtual and multiple inheritance
    It seems as though the copy ctor doesn't copy the vtbl.
    Cheers
    Paul

  • Virtual function overriding

    Hi
    I am having a strange problem in my application. I have a virtual method in a base class which I override in the sub class. In my application I instantiate the subclass . This virtual function is then called from a function in the base class . Most of the time this works okay i.e. the overriden function from the subclass gets called but sometimes , for some reason , the base class function gets called , although I verified that the subclass has been instantiated properly.
    Any ideas what the problem could be ? . Is there any way to debug this , or view the virtual funtion table.
    Any help would be highly appreciated.
    Thanks
    Santosh

    1. Probably you have slicing problem, it happens when you are passing your derived class object where you have defined to pass base class object. In this case your derived class object will be sliced and you will have base class object.
    You have two solutions-
    1. First thing is you should define the functionality of this function in the base class, bcs it seems this functionality belongs to base class as you are trying to use it there.
    2. Dynamically cast the object to your derived class and then call the function. See if it helps.

  • A non abstract child class must implement all pure virtual function of  parent abstract class in c++

    Hi,
    In Indesign SDK there is a class  IActionComponent having two pure virtual functions:
    virtual void
    UpdateActionStates(IActiveContext* ac, IActionStateList *listToUpdateGSysPoint mousePoint = kInvalidMousePoint, IPMUnknown* widget = nil) = 0;
    virtual void
    DoAction(IActiveContext* ac, ActionID actionID, GSysPoint mousePoint = kInvalidMousePoint, IPMUnknown* widget = nil)= 0;
    But, the child class
    class WIDGET_DECL CActionComponent : public IActionComponent
    implements only UpdateActionStates function and not DoAction function.
    There is no compilation error and the code is running fine..HOW
    Can some one please explain me?

    Oops!!! there is a small correction in my C++ program. The JunkMethod is being called from the constructor...like the following code.
    #include <iostream.h>
    #include <stdlib.h>
    class Base
        public:
            Base()
                cout<<"In Base Class constructor..."<<endl;
                JunkMethod();
            void JunkMethod()
                TestAbsFunc();
            virtual void TestAbsFunc()= 0;
    class TestAbstract:public Base
        public:
            TestAbstract()
                cout<<"In Extend Class constructor..."<<endl;
            void TestAbsFunc()
                cout<<"In TestAbsFunc...."<<endl;
    int main()
          TestAbstract test;
          return 0;
    }You can see the change in the constructor of the Base class. JunkMethod is being called, just to bluff the compiler to call the virtual method (so that it won't crib saying that abstract method cannot be called from the constructor). When Java is supporting this functionality without giving any errors, C++ gives errors when you call an abstract method from the constructor or fails to execute when I do some work around like this. Isn't it a drawback of abstract funcationality supported by C++ (I'm not sure if it's a drawback or not)
    Regards,
    Kalyan.

Maybe you are looking for

  • Every time I try to open iPhoto, it quits unexpectedly

    I use a MacBook Pro OS X 10.8.5 I can't tell you what version of iPhoto I use, as it quits to quickly for me to double-check Please can someone help?! The first 50 lines of the Report to send to Apple are as follows: Process:         iPhoto [735] Pat

  • Finding env:\computername through IP address of a remote computer on the network

    I am a beginner in Powershell and as my internship project, I have to write a script for hardware/software inventory of the systems on the network. The issue which I am not able to resolve is that instead of having the names of all the computers in t

  • [SOLVED]Mail Server and Drupal/Gallery2

    I set up this server, that's got a webpage running Drupal with Menalto Gallery2 running.  I've discovered that whenever a new user tries to register with either, no email is sent, and with Gallery2 an error message comes up.  So I figure I need a mai

  • Default  Doc Type for PO

    Hi Friends.. I need your help in solving a Puzzle in SAP. I want to use ME59N automatic po conversion option for creation of PO from PR.Here PR doc type is NB-Standard, I want PO doc type to be my own doc type " CT3 " doc type. I have made below sett

  • Is it normal for the iPhone 5 to stay only 12 hours without charge?

    Hey I bought the iPhone since around 3 months and since that time so far the battery lives only for around 12 hours without 3G and around 6 hours with 3G and I can bearly listen to music for 2-3 hours max if I turn everything off while on the website