据我所知,在DbC方法中,前置条件和后置条件附加到函数中.
我想知道的是,这是否也适用于成员函数.
例如,假设我在每个公共函数末尾的开头使用不变量,成员函数将如下所示:
编辑:(清理我的例子)
void Charcoal::LightOnFire() {
invariant();
in_LightOnFire();
StartBurning();
m_Status = STATUS_BURNING;
m_Color = 0xCCCCCC;
return; // last return in body
out_LightOnFire();
invariant();
}
inline void Charcoal::in_LightOnFire() {
#ifndef _RELEASE_
assert (m_Status == STATUS_UNLIT);
assert (m_OnTheGrill == true);
assert (m_DousedInLighterFluid == true);
#endif
}
inline void Charcoal::out_LightOnFire() {
#ifndef _RELEASE_
assert(m_Status == STATUS_BURNING);
assert(m_Color == 0xCCCCCC);
#endif
}
// class invariant
inline void Charcoal::invariant() {
assert(m_Status == STATUS_UNLIT || m_Status == STATUS_BURNING || m_Status == STATUS_ASHY);
assert(m_Color == 0x000000 …Run Code Online (Sandbox Code Playgroud) design-by-contract invariants member-functions preconditions
为什么以下代码块中的第5行给出了"属性的无效值:缩放"错误?我在Opera 11.62中运行它并在Dragonfly中捕获错误.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
// google chart built here from JSON pulled through php call
</script>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
谢谢.
我已经完成了Qt 4.7 C++教程,并且我已经开始了一个项目来扩展QTreeView的一些功能.
我正在尝试执行以下操作:
我收到以下警告(使用MSVC,命令行):
.\CustomTreeView.cpp(147) : warning C4273: 'CustomTreeView::CustomTreeView' : inconsistent dll linkage
c:\home\jetimms\code\projects\CustomTreeViewTest\CustomTreeView.hpp(31) : see previous definition of '{ctor}'
Run Code Online (Sandbox Code Playgroud)
这些警告还有很多,但它们看起来和上面一样.
另外,我有这些错误:
.\CustomTreeView.cpp(1216) : error C2248: 'NoState' : cannot access protected enumerator declared in class 'QAbstractItemView'
c:\qt\4.7.0\include\qtgui\../../src/gui/itemviews/qabstractitemview.h(304) : see declaration of 'NoState'
c:\qt\4.7.0\include\qtgui\../../src/gui/itemviews/qabstractitemview.h(63) : see declaration of 'QAbstractItemView'
.\CustomTreeView.cpp(1216) : error C2248: 'EditingState' : cannot access protected enumerator declared in class 'QAbstractItemView'
c:\qt\4.7.0\include\qtgui\../../src/gui/itemviews/qabstractitemview.h(307) : see declaration of 'EditingState'
c:\qt\4.7.0\include\qtgui\../../src/gui/itemviews/qabstractitemview.h(63) : see declaration of 'QAbstractItemView'
Run Code Online (Sandbox Code Playgroud)
以上是抱怨相当于以下(在qtreeview.h中),除了用CustomTreeView替换QTreeView之外没有任何变化:
bool …Run Code Online (Sandbox Code Playgroud)