我正在阅读"清洁代码",并且无法弄清楚如何将我的一些功能(通常是构造函数)保持为最多3个参数.
通常我的对象需要大量的信息才能工作 - 我是否应该创建一个小构造函数,然后使用mutator函数为它们提供所有信息?这似乎没有比使用一个大的构造函数更好.
举个例子,我有一个"MovablePatch"类.它允许用户在窗口中拖动方块.它需要几个参数,包括Radius,Color,Renderer,InitialPosition和Visibility.目前我从我的GUI收集所有这些,然后调用:
MovablePatch(int radius, Renderer* renderer, Color color, Position initial, bool visibility)
Run Code Online (Sandbox Code Playgroud)
这些只是我在这堂课中需要的一些东西.任何人都可以建议我如何打包这些信息传递给构造函数?我没有看到任何明显的"打破小班"在这里出现.
我试图在一个大型库中编写一些类的子类.我得到一个"模糊的基础"错误.以下是该问题的可编辑示例:
#include <iostream>
// I can't change these because they are in the library:
class InteractorStyle {};
class InteractorStyleCamera : public InteractorStyle {};
class InteractorStyleImage : public InteractorStyle {};
// These are my subclasses (so I can change them):
class PointSelector : public InteractorStyle {};
class PointSelector2D : public InteractorStyleCamera, public PointSelector
{
// This function has to exist exactly like this (a requirement of the library):
static PointSelector2D* SafeDownCast(InteractorStyle *o)
{
return static_cast<PointSelector2D *>(o);
}
};
int main()
{ …
Run Code Online (Sandbox Code Playgroud) 我已将此添加到课堂评论中:
@link http://www.google.com Google @endlink
Run Code Online (Sandbox Code Playgroud)
但是,当我使用doxygen生成文档时,链接文本确实是"Google",但链接是:
文件:///media/portable/Examples/Doxygen/link/html/classClass1.html
谁能解释出了什么问题?
我正进入(状态:
警告:假设假设(X + c)<X始终为假,则不会发生签名溢出[-Wstrict-overflow]
在这条线上:
if ( this->m_PositionIndex[in] < this->m_EndIndex[in] )
Run Code Online (Sandbox Code Playgroud)
m_PositionIndex
和m_EndIndex
类型itk::Index
(http://www.itk.org/Doxygen/html/classitk_1_1Index.html),他们operator[]
返回一个signed long
.
(这是第37行:https://github.com/Kitware/ITK/blob/master/Modules/Core/Common/include/itkImageRegionConstIteratorWithIndex.hxx for context)
谁能解释一下这会引起什么警告?我没有看到(x+c) < x
任何模式- 因为这只是一个signed long
比较.
我尝试在一个自包含的示例中重现它:
#include <iostream>
namespace itk
{
struct Index
{
signed long data[2];
Index()
{
data[0] = 0;
data[1] = 0;
}
signed long& operator[](unsigned int i)
{
return data[i];
}
};
}
int main (int argc, char *argv[])
{
itk::Index positionIndex; …
Run Code Online (Sandbox Code Playgroud) 我已将FindEigen3.cmake复制到我的源目录中.
然后我补充说:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR})
Run Code Online (Sandbox Code Playgroud)
到我的CMakeLists.txt告诉CMake使用这个.cmake文件.
然后在我的CMakeLists.txt中我做:
FIND_PACKAGE(Eigen3)
Run Code Online (Sandbox Code Playgroud)
我将环境变量EIGEN3_INCLUDE_DIR设置为/ home/doriad/src/eigen
当我运行CMake时,我得到:
-- Could NOT find Eigen3 (missing: EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK) (Required is at least version "2.91.0")
Run Code Online (Sandbox Code Playgroud)
这是Mercurial的新克隆版,所以版本应该至少为3.
有什么建议?
如果我设置模块路径不正确,我会得到一些线索:
Adjust CMAKE_MODULE_PATH to find FindEigen3.cmake or set Eigen3_DIR to the
directory containing a CMake configuration file for Eigen3. The file will
have one of the following names:
Eigen3Config.cmake
eigen3-config.cmake
Run Code Online (Sandbox Code Playgroud)
但是,我没有在Eigen3的源目录或构建目录中找到这些文件.我试图设置Eigen3_DIR =/home/doriad/src/eigen,但这也不起作用.
思考?
谢谢,
大卫
在搜索了一段时间后,我发现他们在groupbox上设置可见边框的方法是使用StyleSheet属性.我补充说:
border: 2px solid gray;
Run Code Online (Sandbox Code Playgroud)
但是有一些问题.
1)组合框内的所有内容也都继承了此设置!
2)边界在标题附近有一个小洞/小块丢失.
这是我正在谈论的图片:
谁知道如何正确地做到这一点?
谢谢,
大卫
我正在尝试将物品制成ComboBox
可检查的物品.我试过这个:
http://programmingexamples.net/wiki/Qt/ModelView/ComboBoxOfCheckBoxes
我在哪里子类化QStandardItemModel
并重新实现了flags()
使项目可检查的功能.然后我把这个模型添加到了ComboBox
.不幸的是,项目不会出现复选框.任何人都可以看到我哪里出错了?
在Fedora 11上编译一些工作代码时,我收到此错误:
/usr/include/c++/4.4.1/cstdarg:56: error: ‘::va_list’ has not been declared
Run Code Online (Sandbox Code Playgroud)
我在用:
[doriad@davedesktop VTK]$ g++ --version
g++ (GCC) 4.4.1 20090725 (Red Hat 4.4.1-2)
Run Code Online (Sandbox Code Playgroud)
有谁知道是什么问题?
我正在尝试将-S
其中一个可执行文件传递给GCC.我试过这个:
set_target_properties(MyTarget PROPERTIES COMPILE_FLAGS "-S")
Run Code Online (Sandbox Code Playgroud)
但我得到"文件格式无法识别;视为链接器脚本"
(没有那条线就可以很好地建造)
这样传球有什么问题-S
吗?或者是否有另一种方法让CMake输出汇编.s文件?
我试图根据类模板参数确定调用哪个版本的成员函数.我试过这个:
#include <iostream>
#include <type_traits>
template<typename T>
struct Point
{
void MyFunction(typename std::enable_if<std::is_same<T, int>::value, T >::type* = 0)
{
std::cout << "T is int." << std::endl;
}
void MyFunction(typename std::enable_if<!std::is_same<T, int>::value, float >::type* = 0)
{
std::cout << "T is not int." << std::endl;
}
};
int main()
{
Point<int> intPoint;
intPoint.MyFunction();
Point<float> floatPoint;
floatPoint.MyFunction();
}
Run Code Online (Sandbox Code Playgroud)
我认为这是说"如果T是int,则使用第一个MyFunction,如果T不是int,则使用第二个MyFunction,但我得到编译器错误"错误:'struct std :: enable_if'中没有类型名为'type'谁能指出我在这里做错了什么?