我有一个类foo
有bar
一个成员变量.
在该类的另一个成员函数中,我正在编写一个lambda函数:
[bar](void){}
Run Code Online (Sandbox Code Playgroud)
但我不能列入bar
捕获列表.这是为什么?
make -C ~/kernel-2.6 M=`pwd` modules
Run Code Online (Sandbox Code Playgroud)
M ='pwd'在上面的行中是什么意思?
我无法理解这个解释:
在尝试构建模块目标之前,M =选项会使makefile移回模块源目录.
你能说得更清楚吗?
我试图在我的程序中包含以下代码,但会出现错误('inet_pton':未找到标识符).
// IPv4:
struct sockaddr_in ip4addr;
int s;
ip4addr.sin_family = AF_INET;
ip4addr.sin_port = htons(3490);
inet_pton(AF_INET, "10.0.0.1", &ip4addr.sin_addr);
s = socket(PF_INET, SOCK_STREAM, 0);
bind(s, (struct sockaddr*)&ip4addr, sizeof ip4addr);
Run Code Online (Sandbox Code Playgroud)
产量
error C3861: 'inet_pton': identifier not found
Run Code Online (Sandbox Code Playgroud)
包括标题
#include <stdio.h>
#include <stdlib.h>
#include "udpDefine.h"
#include <windows.h>
Run Code Online (Sandbox Code Playgroud)
任何帮助可能会错过一些标题或库.
按照这个说明,我设法只产生528字节的大小a.out(当gcc main.c最初给我8539字节的大文件时).
main.c是:
int main(int argc, char** argv) {
return 42;
}
Run Code Online (Sandbox Code Playgroud)
但我已经从这个汇编文件中构建了一个a.out:
电源:
; tiny.asm
BITS 64
GLOBAL _start
SECTION .text
_start:
mov eax, 1
mov ebx, 42
int 0x80
Run Code Online (Sandbox Code Playgroud)
有:
me@comp# nasm -f elf64 tiny.s
me@comp# gcc -Wall -s -nostartfiles -nostdlib tiny.o
me@comp# ./a.out ; echo $?
42
me@comp# wc -c a.out
528 a.out
Run Code Online (Sandbox Code Playgroud)
因为我需要机器码:
objdump -d a.out
a.out: file format elf64-x86-64
Disassembly of section .text:
00000000004000e0 <.text>:
4000e0: b8 01 00 00 00 mov $0x1,%eax …
Run Code Online (Sandbox Code Playgroud) 求解下面两个未知数的两个方程组的系统:
a1,b1,c1,a2,b2和c2由用户自己输入.
我一直试图找到问题的数学解决方案,我似乎无法走远...
到目前为止我尝试过的是:
这是正确的还是有更简单的方法来做到这一点?
当前代码:
#include <iostream>
using namespace std;
int main()
{
int a1, b1, c1, a2, b2, c2;
cout << "Enter the values for the first equation." << endl;
cout << "Enter the value for a1" << endl;
cin >> a1;
cout << "Enter the value for b1" << endl;
cin >> b1;
cout << "Enter the value for c1" << endl;
cin >> c1;
cout << "Enter the values for …
Run Code Online (Sandbox Code Playgroud) 我开始创建一个用抽象代数做事的库.现在我正在尝试创建一个检查集合是否为组的函数.它应该是不言自明的:
在数学中,一个群体是一组元素,同时结合了任何两个元素的运算,形成满足四个条件的第三个元素,称为群组公理,即闭包,关联性,同一性和可逆性.组中最熟悉的一个例子是整数集和加法运算; 任何两个整数的加法形成另一个整数.(http://en.wikipedia.org/wiki/Group_(mathematics))
#include <set>
#include <iostream>
template <typename ObType, typename BinaryFunction>
bool isGroup(const std::set<ObType> & S, BinaryFunction & op)
{
/*
isGroup returns true or false depending on whether the set S
along with the operator op is a group in the Algebraic sense.
That is, S is a group if and only if all the 4 following
conditions are true:
(1) If a, b in S, then a op b in S
(2) If a, …
Run Code Online (Sandbox Code Playgroud) 我正在运行此代码:
#include <iostream>
#include <cstddef>
int main(int argc, char *argv[]){
int a1=0, a2=0;
int a3,a4;
int b1=++a1;
int b2=a2++;
int*p1=&a1;
int*p2=&++a1;
size_t st;
ptrdiff_t pt;
int i=0;
while(true){
printf("i: %d",i++);
}
printf("\n\ni now is: %d\n",i);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么我会观察到图像内存(fiolet)的减少:
传说:
我做了这个通用的Win32项目,而不是CLR.我改变了代码,所以我会看到int最终变成负数.现在while()是:
int i=0;
while(0<++i){
printf("i: %d",i++);
}
printf("\n\ni now is: %d\n",i);
Run Code Online (Sandbox Code Playgroud)
奇怪的是:请看看30000次迭代后发生的事情.为什么我们在图像内存中看到这些波动?我现在可以看到,这可能与VMMap本身有关,因为只有当我选择"启动并跟踪新进程"而不是"查看正在运行的进程"并指向从VS2010运行的exe时才会发生这种情况.这是"已启动和跟踪"流程的屏幕:
我观察到内存的大量分页,这大致开始于图像的下降(这种分页几乎加速并快速触发RAM限制,我设置为2GB):
这是一个只有"查看"的运行进程(从VS2010运行):
那么也许一些受.NET应用程序内存管理影响的问题发生在这里?我还在等待我的int跨越两个补语的边界.
好吧......我必须再次编辑:事实证明,正如之前所想的那样 - 当只查看(未启动)过程时,会出现内存图像效应下降的情况.下面是10分钟后相同过程的附图(仍在等待将int变成负数):
这是:
所以我机器上最大的正2补码是2 147 483 647,最小负值是-2 147 483 648,这很容易验证:
#include <limits>
const int min_int = std::numeric_limits<int>::min();
const int max_int = std::numeric_limits<int>::max();
Run Code Online (Sandbox Code Playgroud)
它给了我相同的结果:-2 147 …
在等式中a + bx = c + dy
,所有变量都是整数.a
,b
,c
,和d
是已知的.我如何找到x
和y
?的整体解决方案?如果我想正确的,就会有解决方案无限多的,通过的最小公倍数分开b
和d
,但我需要的是一个解决方案,我可以计算出的其余部分.这是一个例子:
a = 2
b = 3
c = 4
d = 5
a + bx: (2, 5, 8, 11, 14)
c + dy: (4, 9, 14, 19, 24)
a + bx intersects c + dy at 14, so:
x = 4
y = 2
Run Code Online (Sandbox Code Playgroud)
现在,我循环遍历整数值,x
直到找到y
(伪代码)的整数值:
function integral_solution(int a, int b, int …
Run Code Online (Sandbox Code Playgroud) 有一种称为Cayley-Menger行列式的方法,以便找出3个点是共线的,4个点是共面的,只要给出所有的成对距离.
然而,在二维中,有一种非常简单的方法来确定3点,{A,B,C}是否共线:三角不等式!
!(|AB| + |AC| = |BC|)
和 !(|AB| + |BC| = |AC|)
与 !(|AC| + |BC| = |AB|)
IFF A
,B
,C
不共线
3-D中是否有类似的方法?
使用基于策略的设计,EncapsulatedAlgorithm
:
template< typename Policy>
class EncapsulatedAlgorithm : public Policy
{
double x = 0;
public:
using Policy::subCalculate;
void calculate()
{
Policy::subCalculate(x);
}
protected:
~EncapsulatedAlgorithm() = default;
};
Run Code Online (Sandbox Code Playgroud)
可能有一个Policy
执行子计算的策略.算法不需要子计算:在某些情况下可以使用它来加速算法收敛.因此,为了对此进行建模,假设有三种策略.
一个只是"记录"的东西:
struct log
{
static void subCalculate(double& x)
{
std::cout << "Doing the calculation" << endl;
}
};
Run Code Online (Sandbox Code Playgroud)
一个计算:
struct calculate
{
static void subCalculate(double& x)
{
x = x * x;
}
};
Run Code Online (Sandbox Code Playgroud)
一个人把他们全部带到黑暗中并束缚他们:D - 绝对没有:
struct doNothing
{
static void subCalculate(double& x)
{
// Do …
Run Code Online (Sandbox Code Playgroud)