小编lim*_*imp的帖子

如何解决d中的"冲突"错误?

我正在尝试编译一些D.我编写的代码也使用了std.stringstd.algorithm.我的一个函数调用indexOf一个字符串:不幸的是,显然还有一个indexOf函数std.algorithm,并且编译器不喜欢它:

assembler.d(81): Error: std.algorithm.indexOf!("a == b", string, immutable(char)).indexOf at /usr/share/dmd/src/phobos/std/algorithm.d(4431) conflicts with std.string.indexOf!(char).indexOf at /usr/share/dmd/src/phobos/std/string.d(334)
assembler.d(81): Deprecation: function std.algorithm.indexOf!("a == b", string, immutable(char)).indexOf is deprecated
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?在C++中,我可以使用::明确说出我所在的命名空间...... D怎么样?

conflict namespaces d

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

Haskell中的非直观类型签名

我做了这个(我认为是)相当简单的代码来计算三角形的第三面:

toRadians :: Int -> Double
toRadians d = let deg = mod d 360
              in deg/180 * pi

lawOfCosines :: Int -> Int -> Int -> Double
lawOfCosines a b gamma = sqrt $ a*a + b*b - 2*a*b*(cos (toRadians gamma))
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试将其加载到GHCi时,我收到以下错误:

[1 of 1] Compiling Main             ( law_of_cosines.hs, interpreted )

law_of_cosines.hs:3:18:
    Couldn't match expected type `Double' with actual type `Int'
    In the first argument of `(/)', namely `deg'
    In the first argument of `(*)', namely `deg / 180' …
Run Code Online (Sandbox Code Playgroud)

haskell type-signature

3
推荐指数
2
解决办法
291
查看次数

库在os x上编译libuv?

我正在尝试学习一些libuv,似乎有一本很棒的书可以通过它.但是,这本书没有解释如何实际编译它.我在我从github上提取的代码上运行了make,并使用github(https://github.com/joyent/libuv)中描述的GYP编译.但是我不确定我需要包含哪些库来编译代码.我试着编译这段代码:

/* first.c */
#include <stdio.h>
#include <uv.h>

int main() {
    uv_loop_t *loop = uv_loop_new();

    printf("Now quitting.\n");
    uv_run(loop, UV_RUN_DEFAULT);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我从libuv文件夹中使用以下命令编译它:

gcc -o first first.c build/Release/libuv.a
Run Code Online (Sandbox Code Playgroud)

我得到了以下缺少的符号:

Undefined symbols for architecture x86_64:
  "_CFArrayCreate", referenced from:
      _uv__fsevents_init in libuv.a(fsevents.o)
  "_CFRunLoopAddSource", referenced from:
      _uv__cf_loop_runner in libuv.a(darwin.o)
  "_CFRunLoopGetCurrent", referenced from:
      _uv__cf_loop_runner in libuv.a(darwin.o)
  "_CFRunLoopRemoveSource", referenced from:
      _uv__cf_loop_runner in libuv.a(darwin.o)
  "_CFRunLoopRun", referenced from:
      _uv__cf_loop_runner in libuv.a(darwin.o)
  "_CFRunLoopSourceCreate", referenced from:
      _uv__platform_loop_init in libuv.a(darwin.o)
  "_CFRunLoopSourceSignal", referenced from:
      _uv__cf_loop_signal in libuv.a(darwin.o) …
Run Code Online (Sandbox Code Playgroud)

c shared-libraries libuv

3
推荐指数
2
解决办法
3335
查看次数

即使我有"删除级联",获取"外键约束失败"

我认为ON DELETE CASCADE的意思是这不会发生.:\我有以下表格:

CREATE TABLE Tweets (
    tweetID INTEGER                 NOT NULL AUTO_INCREMENT,
    userID INTEGER                  NOT NULL,
    content VARCHAR(140)            NOT NULL,
    dateTime TIMESTAMP              NOT NULL DEFAULT CURRENT_TIMESTAMP,
    hasPoll INTEGER                 NOT NULL,
    visible INTEGER                 NOT NULL DEFAULT 1,
    PRIMARY KEY (tweetID),
    FOREIGN KEY (userID) REFERENCES Users(userID)
    ON DELETE CASCADE
);

CREATE TABLE Polls (
    pollID INTEGER NOT NULL AUTO_INCREMENT,
    tweetID INTEGER NOT NULL,
    pollOptionText VARCHAR(300),
    PRIMARY KEY (pollID),
    FOREIGN KEY (tweetID) REFERENCES Tweets(tweetID)
);
Run Code Online (Sandbox Code Playgroud)

问题是,当我尝试删除附加了Poll的推文时,我收到以下错误(通过Flask):

_mysql_exceptions.IntegrityError
IntegrityError: (1451, 'Cannot delete or update …
Run Code Online (Sandbox Code Playgroud)

mysql sql cascade foreign-keys

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

如何在打字稿中扩展原始类型?

我想创建一个这样的界面:

interface Show {
  show(): string;
}

function doit(s: Show) {
  return 'Showed: ' + s.show();
}
Run Code Online (Sandbox Code Playgroud)

然后我们可以将它与一个新类一起使用:

class Foo {
  s: string;
  constructor(s: string) { 
    this.s = s; 
  }
  show() {
    return 'Foo with "' + this.s + '"';
  }
}

console.log(doit(new Foo('hello')));
Run Code Online (Sandbox Code Playgroud)

我想为Numbers 做同样的事情。Number例如,在纯 JavaScript 中,我可以使 type满足此接口:

Number.prototype.show = function() { 
  return '' + this; 
}
Run Code Online (Sandbox Code Playgroud)

但 TypeScript 不允许我这样做:

show.ts(18,18): error TS2094: The property 'show' does not exist on value of type 'Number'.
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点?

javascript interface typescript

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

在 emacs 终端中使用 Ctrl-X 命令?

当我在 emacs 内运行终端(使用M-x term)时,我似乎无法使用以 开头的命令C-X,例如C-x o切换窗格或C-x C-c退出。相反,终端本身似乎正在接收这些C-x信号。相比之下,C-c命令是由 emacs 本身接收的。我怎样才能改变这种行为?

emacs terminal

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

C++"使用std :: <type>"vs每次调用std :: <type>

可能重复:
使用std命名空间
为什么'使用命名空间std;' 在C++中被认为是一种不好的做法?

假设我正在使用#include <iostream>C++,我正在制作一个打印语句.我可以选择:

using namespace std;
[...]
cout << "Hello" << endl;
Run Code Online (Sandbox Code Playgroud)

要么

using std::cout;
using std::endl;
[...]
cout << "Hello" << endl;
Run Code Online (Sandbox Code Playgroud)

要么

std::cout << "Hello" << std::endl;
Run Code Online (Sandbox Code Playgroud)

我被引导相信,也许这是不正确的,第一个有点可以避免,因为它会给你的程序增加许多不必要的膨胀.但是,我不知道第二种和第三种风格在性能方面是否存在任何差异.我看到的大多数使用库的代码都倾向于使用第三种风格; 但对我来说,如果在使用第二个方面没有权衡,它似乎是最干净,最易读的方法,特别是如果你对相关的函数或对象进行大量调用.

任何人都可以开导我吗?

c++ namespaces using

2
推荐指数
2
解决办法
1675
查看次数

已安装iOS 5.1模拟器,但它不会显示在方案列表中

我有XCode 4.4.1,默认情况下包含iOS 6.0模拟器.但最初,我想为iOS 5.1构建一些应用程序.我去了XCode-> Preferences-> Downloads并安装了iOS 5.1模拟器.但是在我的项目中(包括我从那时起创建的项目),可用的Schemes列表仅包含"iOS Device","iPad 6.0 Simulator"和"iPhone 6.0 Simulator".如何获得我下载的iPhone 5.1模拟器?

xcode simulator

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

一个进程可以有两个PID吗?

我正在研究计算机系统,我已经创建了这个非常简单的函数,用于fork()创建子进程.如果它是子进程,则fork()返回pid_t0.但是getpid()在这个子进程中调用该函数会返回一个不同的非零pid.在我下面的代码中,newPid只在程序的上下文中有意义,而不是对操作系统有意义吗?它可能只是一个相对值,用父母的pid来衡量?

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>

void unixError(char* msg)
{
    printf("%s: %s\n", msg, strerror(errno));
    exit(0);
}

pid_t Fork()
{
    pid_t pid;
    if ((pid = fork()) < 0)
        unixError("Fork error");
    return pid;
}


int main(int argc, const char * argv[])
{
    pid_t thisPid, parentPid, newPid;
    int count = 0;
    thisPid = getpid();
    parentPid = getppid();

    printf("thisPid = %d, parent pid = %d\n", thisPid, parentPid); …
Run Code Online (Sandbox Code Playgroud)

c fork pid

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

如何指定XCode存储已编译二进制文件的位置?

我正在用C++ 11编写,由于某种原因,我无法获得gcc来编译它,所以我一直在使用XCode.但是,我正在编写从命令行获取参数的程序,因此我需要能够从shell运行它们.现在,XCode正在将它编译的二进制文件埋藏在一个深度和不方便的位置(/ Users/username/Library/Developer/XCode/DerivedData/ProjectName/Build/Products/Debug/... yikes!).我希望能够为他们指定一个更好的位置,也可能是另一个名称.我正在使用XCode 4.5.2.任何人都可以帮我解决这个问题吗?

xcode binary-data

2
推荐指数
2
解决办法
6621
查看次数