我用来Doxygen记录我的 C++ 代码。所有内容都以 HTML 格式很好地输出,除了像下面这样的属性/变量不是(根本不是)。
/**
* Flag to check whether the variable is once initialized or not
*/
bool initialized_;
Run Code Online (Sandbox Code Playgroud)
知道会出什么问题吗?
编辑
initialized_是类成员变量。
我想知道 C++ 自动创建多个无限数量的对象(0..n)的方法。用例如下:
假设我有一个脚本,用户必须输入相关数据(宽度、长度、高度),稍后在 Box 类中将包含这些数据。
Box
{
...
...
double width;
double length;
double height;
...
...
}
Run Code Online (Sandbox Code Playgroud)
该脚本如下所示:
<id="width" value="1"/>
<id="length" value="3"/>
<id="height" value="3"/>
<id="width2" value="3"/>
<id="length2" value="3"/>
<id="height2" value="4"/>
<id="width3" value="2"/>
<id="length3" value="3"/>
<id="height3" value="3"/>
Run Code Online (Sandbox Code Playgroud)
换句话说,我如何实例化那些事先不知道对象数量的对象,而是取决于用户输入了多少框信息(宽度等)。
另外,是否有任何设计模式?
我运行了一个命令svn mkdir file:///home/abc/workspace/svn/proj/trunk,就是当我运行cd命令时无法导航的trunk目录.但是,当我跑步时svn checkout file:///home/abc/workspace/svn/,它给出了以下内容:
A svn/proj
A svn/proj/trunk
Checked out revision
Run Code Online (Sandbox Code Playgroud)
我如何理解这一点,它svn mkdir与UNIX mkdir命令有什么不同?
我对 C++ 函数/方法设计有如下困惑:
1.
class ArithmeticCalculation
{
private:
float num1_;
float num2_;
float sum_;
void addTwoNumbers();
};
Run Code Online (Sandbox Code Playgroud)
2.
class ArithmeticCalculation
{
private:
float addTwoNumbers(float num1, float num2);
};
Run Code Online (Sandbox Code Playgroud)
在 1. 中,基本上可以声明一个类变量,而 void addTwoNumbers() 只会实现它并分配给类变量 ( sum_)。我发现使用 1. 更干净,但使用 2. 看起来对于函数使用更直观。
考虑到函数/方法不仅限于这个基本的加法功能,哪一个实际上是最佳选择——我的意思是一般来说如何决定使用 return 还是简单的 void?
我在另一个内部使用python模块时遇到问题.用例如下:
请考虑以下情形.相应地评论了该错误.
在文件A.py中:
import B
...
...
Run Code Online (Sandbox Code Playgroud)
在文件B.py中:
import C
import A
c_func = C.func1() # works perfectly
a_func = A.func2() # Error: 'module' object has no attribute 'func2'
...
...
Run Code Online (Sandbox Code Playgroud)
在文件C.py中:
...
...
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?提前致谢.
我编写了一个模拟abc模块和模块使用的代码properties.但是,似乎我无法访问width和height变量.代码如下:
from abc import ABCMeta, abstractmethod
class Polygon:
__metaclass__ = ABCMeta
@abstractmethod
def compute_area(self): pass
def __init__(self):
self.width = None
self.height = None
@property
def width_prop(self):
return self.width
@property
def height_prop(self):
return self.height
@width_setter.setter
def width_setter(self, width):
self.width = width
@height_setter.setter
def height_setter(self, height):
self.height = height
class Triangle(Polygon):
def compute_area(self):
return 0.5 * width * height
if __name__ == "__main__":
tri = Triangle()
tri.height_setter(20)
tri.width_setter(30)
print "Area of the triangle = …Run Code Online (Sandbox Code Playgroud)