小编Jer*_*rry的帖子

在流星0.6.4.1/coffeescript中,变量可见性如何工作?

我是meteor和coffeescript的新手.我正在使用非官方流星常见问题解答中建议的文件布局.在文件集/ C.coffee中,我有

C = new Meteor.Collection 'C'
console.log "C: #{C}"
Run Code Online (Sandbox Code Playgroud)

在文件服务器/ main.coffee中,我有

C.insert {test: 'test'}
Run Code Online (Sandbox Code Playgroud)

当我启动流星时,我在控制台上看到:

C: [object Object]
ReferenceError: C is not defined
    at app/server/main.coffee.js:5:1
    at /home/xxx/yyy/.meteor/local/build/server/server.js:298:12
Run Code Online (Sandbox Code Playgroud)

如何在collections/C.coffee之外的文件中提供C?

更新:添加@到C修复了顶级问题.但它仍然失败:

   Meteor.methods
        test: (statement) ->
             @C.insert {test: 'test'}
Run Code Online (Sandbox Code Playgroud)

它失败并出现错误 TypeError: Cannot call method 'insert' of undefined

coffeescript meteor

8
推荐指数
1
解决办法
1261
查看次数

以类方法为参数的 C++ 模板

是否可以将类方法作为参数传递给模板?例如:

template<typename T, void(T::*TFun)()>
void call(T* x) {
    x->TFun();
}

struct Y {
    void foo();
};

int main() {
    Y y;
    call<Y,&Y::foo>(&y);  // should be the equivalent of y.foo()
}
Run Code Online (Sandbox Code Playgroud)

如果我尝试编译上述内容,我会得到:

main.cpp: In instantiation of void call(T*) [with T = Y; void (T::* TFun)() = &Y::foo]:
main.cpp:12:23:   required from here
main.cpp:4:5: error: struct Y has no member named TFun
     x->TFun();
     ^
Run Code Online (Sandbox Code Playgroud)

这可能吗,如果可能,语法是什么?

c++ templates

4
推荐指数
1
解决办法
1411
查看次数

为什么我的 FParsec 解析器无法识别块注释?

我正在尝试使用 FParsec 解析 C 风格注释。不知道为什么会失败:

我的解析器代码:

let openComment : Parser<_,unit>  = pstring "/*"
let closeComment : Parser<_,unit> = pstring "*/"
let comment = pstring "//" >>. restOfLine true
                <|> openComment >>. (charsTillString "*/" true System.Int32.MaxValue) |>> Comment
                //<|> openComment >>. manyCharsTill anyChar closeComment |>> Comment
let spaceComments = many ((spaces1 |>> IgnoreU) <|> comment)
let str s  = spaceComments >>. pstring s .>> spaceComments
Run Code Online (Sandbox Code Playgroud)

测试线束:

let testStr = @"
// test comment
/* a block comment
   */
   x  // another …
Run Code Online (Sandbox Code Playgroud)

f# fparsec

1
推荐指数
1
解决办法
50
查看次数

标签 统计

c++ ×1

coffeescript ×1

f# ×1

fparsec ×1

meteor ×1

templates ×1