我有一个很大的遗留代码库,包含非常复杂的makefile,有很多变量.有时我需要改变它们,我发现很难弄清楚为什么改变不按照我的预期运作.我想找到的是一个基本上对"make"过程进行逐步调试的工具,我会给它一个目录,我将能够在不同的点看到不同变量的值.处理.没有任何调试标志似乎能告诉我我想要什么,虽然我可能会遗漏一些东西.有谁知道这样做的方法?
在C++中,给出纯虚函数的实现是合法的:
class C
{
public:
virtual int f() = 0;
};
int C::f()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
你为什么要这样做?
相关问题:C++ faq lite包含一个例子:
class Funct {
public:
virtual int doit(int x) = 0;
virtual ~Funct() = 0;
};
inline Funct::~Funct() { } // defined even though it's pure virtual; it's faster this way; trust me
Run Code Online (Sandbox Code Playgroud)
我不明白为什么析构函数被声明为纯虚拟然后实现; 我不明白为什么这应该更快的评论.
当我想将一个新文件拆分成几个提交时,我可以git add -N <file>然后使用交互式分段线git gui.但是,当我在分段时犯了错误时,git gui不会让我取消单独的行,因为它是一个新文件(这对我来说似乎是个错误).当然,我总是可以取消整个文件并重新开始,但我想知道是否有更有效的方法.
我在用git 1.7.5.
为了澄清,这个问题特定于新的 aka 未跟踪文件!
两种语言都声称可以修复JavaScript的缺陷.我想了解CoffeeScript和Dart(编译为JavaScript)如何实现这一目标的主要区别.特别是,
我对个人偏好,采用率,工具支持或特定用途的有用性不感兴趣.
像我这样的大多数C++程序员在某些方面犯了以下错误:
class C { /*...*/ };
int main() {
C c(); // declares a function c taking no arguments returning a C,
// not, as intended by most, an object c of type C initialized
// using the default constructor.
c.foo(); // compiler complains here.
//...
}
Run Code Online (Sandbox Code Playgroud)
现在虽然错误很明显,一旦你知道它我想知道这种本地函数声明是否有任何明智的用途,除了你可以这样做 - 特别是因为没有办法在同一个函数中定义这样的本地函数块; 你必须在其他地方定义它.
我认为Java风格的本地类是一个非常好的功能,我倾向于经常使用,特别是匿名排序.甚至本地C++类(可以具有内联定义的成员函数)也有一些用处.但是这个没有定义的本地函数声明对我来说似乎很尴尬.它只是一个C-legacy还是有一些我不知道的更深层次的用例?
编辑对于非信徒:C c()是不是一个函数指针声明.
这个计划
int main()
{
void g();
cout << "Hello ";
g();
return 0;
}
void g()
{
cout << …Run Code Online (Sandbox Code Playgroud) 假设我有这些抽象类,Foo并且Bar:
class Foo;
class Bar;
class Foo
{
public:
virtual Bar* bar() = 0;
};
class Bar
{
public:
virtual Foo* foo() = 0;
};
Run Code Online (Sandbox Code Playgroud)
进一步假设我有派生类ConcreteFoo和ConcreteBar.我想协同改进foo()和这样的bar()方法的返回类型:
class ConcreteFoo : public Foo
{
public:
ConcreteBar* bar();
};
class ConcreteBar : public Bar
{
public:
ConcreteFoo* foo();
};
Run Code Online (Sandbox Code Playgroud)
这将无法编译,因为我们心爱的单通道编译器不知道ConcreteBar将继承Bar,因此这ConcreteBar是一个完全合法的协变返回类型.普通的前向声明ConcreteBar也不起作用,因为它没有告诉编译器有关继承的任何信息.
这是C++的一个缺点,我将不得不忍受或者是否真的有办法解决这个难题?
使用dlopen加载其他包时可能导致以下错误:
dlopen($(OBJ_DIR)/Test-20091217211256.ob, 6): no suitable image found. Did find:
$(OBJ_DIR)/Test-20091217211256.ob: can't map
Run Code Online (Sandbox Code Playgroud)
在此错误之前,该进程会分配大量内存.
($(OBJ_DIR)在实际路径的错误中替换,使其更清晰).
我想创建一个具有两个属性的自定义QML组件,one并且two在未初始化时应具有默认值.特别是,如果two应该得到一个初始值one.以下代码
Rectangle {
property int one: 1
property int two: 2 * one
}
Run Code Online (Sandbox Code Playgroud)
但是会创建一个属性绑定:每当one更改时,two都会更新为新值2 * one.如何在不创建绑定的情况下初始化two为值2 * one?
在努力保持正确性的同时,我经常发现自己正在编写这样的代码
class Bar;
class Foo {
public:
const Bar* bar() const { /* code that gets a Bar somewhere */ }
Bar* bar() {
return const_cast< Bar* >(
static_cast< const Foo* >(this)->bar());
}
};
Run Code Online (Sandbox Code Playgroud)
对于很多方法,比如bar().编写这些非const方法,手动调用常量方法是乏味的; 此外,我觉得我在重复自己 - 这让我心疼.
我该怎么做才能减轻这个任务?(不允许使用宏和代码生成器.)
编辑:除了litb的解决方案,我也喜欢我自己的解决方案.:)
我有以下qml应用程序:
import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Layouts 1.0
import QtQuick.Window 2.0
ApplicationWindow {
id: window
width: 480
height: 240
RowLayout {
Rectangle {
width: window.height
height: window.height
radius: window.height / 2
color: "black"
}
Canvas {
id: canvas
width: window.height
height: window.height
onPaint: {
var ctx = canvas.getContext('2d');
var originX = window.height / 2
var originY = window.height / 2
var radius = window.height / 2
ctx.save();
ctx.beginPath();
ctx.arc(originX, originY, radius, 0, 2 * Math.PI);
ctx.fillStyle = Qt.rgba(0, …Run Code Online (Sandbox Code Playgroud) c++ ×4
qml ×2
canvas ×1
coffeescript ×1
covariance ×1
dart ×1
debugging ×1
definition ×1
dlopen ×1
dry ×1
function ×1
git ×1
javascript ×1
local ×1
macos ×1
makefile ×1
performance ×1
pure-virtual ×1
qt ×1
unstage ×1