我是C++的新手,所以我提前为我的问题的世俗性质道歉.
我被要求将以下内联函数从头文件移动到源文件.但是我很难在源文件中获得正确的语法.这是头文件中的内联函数:
class G1FRViewOption
{
public:
enum ViewType {partyView, contraView, unknown} ;
G1FRViewOption() : m_view (nullString )
, m_viewType (unknown )
, m_isValid (false ) {initialise();}
G1FRViewOption(const RWCString view) : m_view (view )
, m_viewType (unknown )
, m_isValid (false ) {initialise();}
void initialise()
{
static RWCString views[] = {"party","contra"} ;
for (int vt=counterpartyView; vt<unknown; vt++)
if (m_view.compareTo(views[vt], RWCString::ignoreCase)==0)
{
m_viewType = (ViewType) vt ;
m_isValid = true ;
break ;
}
}
RWCString getErrorMessage()
{
return "Invalid " + getFieldLabel() + " given. Valid values are party, contra.";
}
G1FRViewOption & operator = (const G1FRViewOption & other)
{
this->m_view = other.m_view ;
this->m_viewType = other.m_viewType ;
this->m_isValid = other.m_isValid ;
return *this ;
}
RWBoolean is (ViewType viewType) const {return viewType == m_viewType ;}
RWBoolean isValid () const {return m_isValid ;}
const RWCString & toString () {return m_view ;}
static const RWCString & getFieldLabel () { static RWCString value = "View" ; return value ; }
static const FieldDefinition & getFieldDefinition () { static const FieldDefinition fd (getFieldLabel(), 13) ; return fd ; }
private:
RWCString m_view ;
ViewType m_viewType ;
RWBoolean m_isValid ;} ;
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
提前谢谢了.
C++新手!
将函数从标题中移出到cpp文件中,首先创建相应的cpp文件(如果它不存在),然后将函数的主体逐个复制到该文件中,在其名称前加上类的名称和两个冒号::,像这样:
void initialise()
{
static RWCString views[] = {"party","contra"} ;
for (int vt=counterpartyView; vt<unknown; vt++)
if (m_view.compareTo(views[vt], RWCString::ignoreCase)==0)
{
m_viewType = (ViewType) vt ;
m_isValid = true ;
break ;
}
}
Run Code Online (Sandbox Code Playgroud)
从标题变成
void initialise();
Run Code Online (Sandbox Code Playgroud)
在标题中,和
void G1FRViewOption::initialise()
{
static RWCString views[] = {"party","contra"} ;
for (int vt=counterpartyView; vt<unknown; vt++)
if (m_view.compareTo(views[vt], RWCString::ignoreCase)==0)
{
m_viewType = (ViewType) vt ;
m_isValid = true ;
break ;
}
}
Run Code Online (Sandbox Code Playgroud)
在cpp文件中.
| 归档时间: |
|
| 查看次数: |
283 次 |
| 最近记录: |