Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error C2259:cannot instantiate abstract class

Tags:

c++

c++builder

this is the error message with compiler of visual studio 2010(although it has no problem with compiler of micrsoft visual studio 2003)

error C2259: 'user_param::UserParamB2<std::string>' : cannot instantiate abstract class due to following members:
    'bool user_param::UserParamBase::readonly(bool)' : is abstract
    c:\qc\qc_daq\src\hfgui3\userparambase.h(128) : see declaration of 'user_param::UserParamBase::readonly'
    'bool user_param::UserParamBase::readonly(void)' : is abstract
    c:\qc\qc_daq\src\hfgui3\userparambase.h(127) : see declaration of 'user_param::UserParamBase::readonly'
    'SIZE user_param::UserParamBase::winSize(void)' : is abstract
    c:\qc\qc_daq\src\hfgui3\userparambase.h(129) : see declaration of 'user_param::UserParamBase::winSize'

My source code looks like as follows:

class UserParamBase : public UserParamName
{
    public:
        virtual bool    readonly() =0;
        virtual bool    readonly(bool bReadonly)=0;
        virtual SIZE    winSize()=0;    
        virtual bool    get()=0;
        virtual void    create(CWnd* pParentWnd,const RECT& rect)=0;
        virtual void    close()=0;  
        virtual void    update()=0;
}

...
template <>
class UserParam< string > : public UserParamB2< string >
{
public:
bool get()
{
    AutoCritSec acsWnd(m_csWnd, true);
    if(m_wnd.combobox && m_wnd.combobox->GetSafeHwnd()) {
        CString text;
        m_wnd.combobox->GetWindowText(text);
        this->assign((LPCSTR) text);
    } else if(m_wnd.wnd && m_wnd.wnd->GetSafeHwnd()) {
        char* psz=NULL;
        string s;
        unsigned uSize = m_wnd.wnd->GetWindowTextLength()+1;
        try {
            psz=new char[uSize];
            m_wnd.wnd->GetWindowText(psz,uSize);
            s.assign(psz);
        }
        catch(...) {
            if(psz) delete [] psz;
            throw;
        }
        if(psz) delete [] psz;
        s.erase(std::remove(s.begin(),s.end(),'\r'),s.end());
        this->assign(s);
    }
    return true;
}

The error message occurs at the this->assign(s); statement.

like image 338
user1107855 Avatar asked Dec 07 '25 03:12

user1107855


1 Answers

It's hard to be specific since you did not post any code, only unformatted compiler output. However, it seems that you created a subclass of a class with abstract methods readonly(bool), winSize(void) and you did not implement these functions in subclass. Therefore, your subclass remained abstract. Implement these methods.

like image 64
ondrisko Avatar answered Dec 08 '25 18:12

ondrisko