Tag: C#的

std :: function <>和一个标准函数指针之间的区别?

std :: function <>和一个标准函数指针有什么区别? 那是: typedef std::function<int(int)> FUNCTION; typedef int (*fn)(int); 他们实际上是一样的东西吗?

如何解决错误LNK2019:无法parsing的外部符号 – 函数?

我得到这个错误,但我不知道如何解决它。 我正在使用Visual Studio 2013.我提出了解决scheme名称MyProjectTest这是我的testing解决scheme的结构: – function.h #ifndef MY_FUNCTION_H #define MY_FUNCTION_H int multiple(int x, int y); #endif -function.cpp #include "function.h" int multiple(int x, int y){ return x*y; } – main.cpp #include <iostream> #include <cstdlib> #include "function.h" using namespace std; int main(){ int a, b; cin >> a >> b; cout << multiple(a, b) << endl; system("pause"); […]

为.NET应用程序存储用户设置的最佳方式是什么?

我有一个.NET 2.0 Windows窗体应用程序。 商店用户设置的最佳位置在哪里(考虑Windows指南)? 有些人指向Application.LocalUserAppDataPath 。 但是,这会创build一个文件夹结构,如: C:\ Documents and Settings \ user_name \ Local Settings \ Application Data \ company_name \ product_name \ product_version \ 如果我发布我的应用程序的版本1,并在那里存储一个XML文件,然后发布版本2,这将更改为不同的文件夹,对不对? 无论应用程序版本如何,我都希望每个用户都有一个文件夹来存储设置。

testingunit testing数据文件的path

我目前在VS 2008中使用标准的Microsoftunit testing套件.ReSharper 4.5也被安装。 我的unit testing依赖于预加载数据文件的TestInitialize方法。 这个testing数据文件的path将会有所不同,具体取决于我是否使用标准的Ctrl-R + Ctrl-T命令与Resharperunit testing执行命令在VS 2008中运行unit testing。 我的TestInitialize方法如何知道unit testing数据文件的正确path? 更新: testing数据足够大,我不想把它推入一个string,所以宁愿保留它作为外部文件。 我的testing项目的文件结构是使用MVC应用程序创build的标准unit testing项目的文件结构。 在testing项目的根目录下,创build了一个名为“testing数据”的新文件夹。 这是我想要访问这个文件夹,无论testing运行。

如何编写一个信号处理程序来捕获SIGSEGV?

我想写一个信号处理程序来捕获SIGSEGV。 我保护一块内存以供读取或写入使用 char *buffer; char *p; char a; int pagesize = 4096; mprotect(buffer,pagesize,PROT_NONE) 这可以保护从缓冲区开始的页面缓冲区的任何读写操作。 其次,我尝试阅读记忆: p = buffer; a = *p 这将生成一个SIGSEGV,我的处理程序将被调用。 到现在为止还挺好。 我的问题是,一旦处理程序被调用,我想通过做改变访问写入的内存 mprotect(buffer,pagesize,PROT_READ); 并继续我的代码正常运作。 我不想退出这个function。 在未来写入相同的内存,我想再次捕捉信号,并修改写权限,然后logging该事件。 这里是代码 : #include <signal.h> #include <stdio.h> #include <malloc.h> #include <stdlib.h> #include <errno.h> #include <sys/mman.h> #define handle_error(msg) \ do { perror(msg); exit(EXIT_FAILURE); } while (0) char *buffer; int […]

为什么声明浮动时需要“f”?

例: float timeRemaining = 0.58f; 为什么在数字的最后需要f ?

为什么没有使用申报工作来解决钻石问题呢?

请考虑下面的代码: struct A { void f() { } }; struct B1 : A { }; struct B2 : A { }; struct C : B1, B2 { void f() // works { B1::f(); } //using B1::f; // does not work //using B1::A::f; // does not work as well }; int main() { C c; cf(); […]

什么是正确的方法来获得(-1)^ n?

许多algorithm需要计算(-1)^n (两个整数),通常作为一系列因子。 也就是说,对于奇数n是-1对于偶数n是1 。 在C或C ++环境中,经常会看到: #include<iostream> #include<cmath> int main(){ int n = 13; std::cout << std::pow(-1, n) << std::endl; } 什么更好或惯例? (或者是其他东西), std::pow(-1, n) std::pow(-1, n%2) (n%2?-1:1) (1-2*(n%2)) // (gives incorrect value for negative n) 编辑:另外,用户@SeverinPappadeux提出了另一种基于(全局?)数组查找的替代scheme。 我的版本是: const int res[] {-1, 1, -1}; // three elements are needed for negative modulo results const int* […]

如何迭代std :: set?

我有这个代码: std::set<unsigned long>::iterator it; for (it = SERVER_IPS.begin(); it != SERVER_IPS.end(); ++it) { u_long f = it; // error here } 没有->first值。 我如何获得价值?

指针和参考参数之间的区别?

这些是一样的: int foo(bar* p) { return p->someInt(); } 和 int foo(bar& r) { return r.someInt(); } 忽略空指针的潜力。 无论someInt()是虚拟的还是通过一个bar或bar的子类,这两个函数在function上是否相同? 这是否切片什么: bar& ref = *ptr_to_bar;