2

我已经完成了我在网上可以找到的所有内容,但似乎我错过了一些非常基本的东西,在这个问题上花了这么多时间并没有让事情变得更容易,所以我会继续在这里寻求帮助,看看是否你可以找到我做错了什么。

这是代码:

jControl.h

#ifndef _JCONTROL_H
#define _JCONTROL_H

namespace view
{


class jControl
{

public:


HWND hwnd;
HWND hParent;
HBITMAP hbitmap;
std::string text;
HFONT hFont;
COLORREF textColor;
COLORREF backgroundColor;
RECT updateRegion;
bool isUpdateRegion;

public:


jControl (  );

jControl ( HWND parent, HINSTANCE hInstance, WORD bitmap );

~jControl (  );

virtual void show (  );

virtual void hide (  );

virtual void disable (  );

virtual void enable (  );

virtual std::string getText (  );

virtual void setText ( std::string txt );

virtual void setUpdateRegion ( RECT rect );

virtual void setTextColor ( COLORREF crf );

virtual void setBackgroundColor ( COLORREF crf );

virtual void setFont ( HFONT font );

virtual bool setRange ( int range );

virtual bool setStep ( int step );

};

};

#endif

jControl.cpp

#include "jControl.h"

namespace view
{



jControl::jControl(  ){};


jControl::jControl ( HWND parent, HINSTANCE hInstance, WORD bitmap ) 
                    : hParent ( parent ), hbitmap ( NULL ), isUpdateRegion ( false ), textColor (  RGB ( 255, 255, 255 )  ), backgroundColor (  RGB ( 54, 54, 54 )  )
{

    hFont = ::CreateFont ( 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Myriad Pro" );

    if ( bitmap != 0 )  hbitmap = LoadBitmap (  hInstance, MAKEINTRESOURCE ( bitmap )  );

};


jControl::~jControl (  ) 
{ 

  if ( hbitmap )    DeleteObject ( hbitmap );

  if ( hFont )      DeleteObject ( hFont );

  if ( hwnd )       DestroyWindow ( hwnd ); 

};

void jControl::show(  ) {   ::ShowWindow( hwnd, SW_SHOW );  };

void jControl::hide(  ) {   ::ShowWindow( hwnd, SW_HIDE );  };

void jControl::disable (  ) {   EnableWindow ( hwnd, false );   };

void jControl::enable (  )  {   EnableWindow ( hwnd, true );    };

std::string jControl::getText (  )  {   return text;    };

void jControl::setText ( std::string txt )  {   text = txt;     InvalidateRect ( hwnd, NULL, true );    };

void jControl::setUpdateRegion ( RECT rect )    {   updateRegion = rect;    isUpdateRegion = true;  };

void jControl::setTextColor ( COLORREF crf )    {  textColor = crf;  };

void jControl::setBackgroundColor ( COLORREF crf )  {  backgroundColor = crf; ::InvalidateRect ( hwnd, NULL, true );  };

void jControl::setFont ( HFONT font )   {   hFont = font;   };

bool jControl::setRange ( int range )   {   return true;    };

bool jControl::setStep ( int step )     {   return true;    };

};

jProgressBar.h

#ifndef _JPROGRESSBAR_H
#define _JPROGRESSBAR_H




/**     * Parent class include      */
#ifndef _JCONTROL_H
   #include  "../jControl/jControl.h"
#endif


namespace view
{

class jProgressBar : public jControl
{


public:

jProgressBar ( std::string txt, int x, int y, int width, int height, HWND parent, HINSTANCE hInstance, WORD bitmap );

~jProgressBar (  );

std::string getText (  );

void setText ( std::string txt );

bool setRange ( int range );

bool setStep ( int step );


};

};

#endif

jProgressBar.cpp

#include "jProgressBar.h"

namespace view
{


jProgressBar::jProgressBar( std::string txt, int x, int y, int width, int height, HWND parent, HINSTANCE hInstance, WORD bitmap ) 
                  : jControl( parent, hInstance, bitmap )
{

    hwnd =  CreateWindowEx ( WS_EX_TOPMOST, PROGRESS_CLASS, txt.c_str(), WS_CHILD | WS_CLIPSIBLINGS | WS_CHILD, x, y, width, height, parent, 0, hInstance, 0 );

};

jProgressBar::~jProgressBar (  ){};

bool jProgressBar::setRange ( int range )
{ 

    if ( SendMessage (  hwnd, PBM_SETRANGE, 0, MAKELPARAM ( 0,  range )  ) != 0 )   return true;

    return false;

};

bool jProgressBar::setStep ( int step )
{ 

     if ( SendMessage (  hwnd, PBM_SETSTEP, ( WPARAM ) step, 0  ) != 0 )    return true;

    return false;

};


};

这是错误:

[Linker error] jProgressBar/jProgressBar.cpp:14: undefined reference to `vtable for view::jProgressBar' 

我收到关于 JProgressBar 的构造函数和析构函数的错误。

4

1 回答 1

5

问题可能出在以下几行:

std::string getText(  ); 

void setText( std::string txt );

在 jProgressBar.h

请在 Cpp 中提供此函数的定义或将其从标头中删除,我认为它应该编译。主要原因是:你已经用声明覆盖了子类中的虚函数,但没有给出方法的定义。编译器知道该函数,但链接器无法找到定义 例如:

class Base
{
    virtual void f() = 0;
}
class Derived : public Base
{
    void f();
}
于 2013-07-26T06:17:47.100 回答