是否可以使用与此(错误)语法类似的内容进行宏选择?
#define FLAG MULT
#ifdef FLAG ADD
int op(int a, int b) {return a + b;}
#endif
#ifdef FLAG MULT
int op(int a, int b) {return a * b;}
#endif
Run Code Online (Sandbox Code Playgroud) 我有两个选择:
class X{
int* x;
int size = ...;
void create() {
x = new int[size];
use();
delete [] x;
}
void use() {//use array}
};
Run Code Online (Sandbox Code Playgroud)
要么:
class X{
int size = ...;
void create(){
int x[size];
use(x);
}
void use(int arg[]) {//use arg}
};
Run Code Online (Sandbox Code Playgroud)
哪个更好?
我有这些陈述:
data SL a = SR (Integer -> (a, Integer))
deriving(Show)
instance Monad SL where
return k = SR (\st -> (k, st))
xx::SL Integer
xx = return 4
Run Code Online (Sandbox Code Playgroud)
然后我做:
let SR f = xx
Run Code Online (Sandbox Code Playgroud)
我现在有:
xx :: SL Integer
f :: Integer -> (Integer, Integer)
Run Code Online (Sandbox Code Playgroud)
但我不明白为什么.也许我错过了语法的含义let DATACONSTRUCTOR ...
你能帮我吗?
其实我不知道如何定义这个习语.
在某些代码中我有红色的东西:
ClassWithAMessage c = "This is the message";
Run Code Online (Sandbox Code Playgroud)
我希望阅读的地方:
ClassWithAMessage c("This is the message");
Run Code Online (Sandbox Code Playgroud)
我不知道如何重现这种行为,有人可以提供一些信息或玩具示例吗?
我正在尝试编译C++的一些代码,这在Windows系统中可以正常运行.
我有很多错误,如下所示:
code:
..
39 set<Node<T>*>::iterator child;
...
Run Code Online (Sandbox Code Playgroud)
g++ 给我错误:
Node.h:39: error: expected ‘;’ before ‘child’
Run Code Online (Sandbox Code Playgroud)
这只是一个例子.你能给我一些如何解决它的提示吗?
鉴于此代码段
def doSomething() = {
val associations : HashMap[Int, Int] = function_that_create_a_hashmap
println("something")
}
Run Code Online (Sandbox Code Playgroud)
当doSomething终止时,系统变量associations去分配呢?我应该在它上面调用一些析构函数(.clear在这种情况下可能)或者该操作没用吗?