RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-198501

pank's questions

Martin Hope
pank
Asked: 2020-06-16 17:20:09 +0000 UTC

元命令行工具?

  • 0

对有哪些程序可以结合其他程序的工作感兴趣。类似的东西Makefile。这将在顶层提供一些抽象(规则、目标、源、目标......),它们可以通过编写一系列特定的命令行实用程序和其他程序来实现。

这是必要的,以便让用户能够执行命令,而无需考虑如何在后台执行命令。

同时对于开发人员来说,更容易开发他们的实现,同时最好是跨平台的。如果有一个内置的检查这个程序是否存在于系统中也会很棒,如果不存在,那么该实用程序将提供安装所有必要的依赖项。

我正在考虑在nodejs.

到目前为止我很满意Makefile,但突然间有更有趣的事情发生了。在启动Makefile时,如果用户没有必要的包,那么每次启动后他都需要安装他停止的包Makefile。并且对于跨平台,并非一切都那么好。

linux
  • 1 个回答
  • 10 Views
Martin Hope
pank
Asked: 2020-11-21 22:15:29 +0000 UTC

如何为 HTML 5 Canvas 实现游戏相机(相机放大/缩小)?

  • 4

实际上,任务是实现一个相机,它可以跟随游戏世界中的玩家,并能够从玩家放大/缩小相机。

跟随播放器实现相机非常简单:

ctx.save();
ctx.translate(-camera.leftTopPos.x, -camera.leftTopPos.y);
// Рисуем игрока и игровой мир
ctx.restore();

它在哪里camera:

var camera = {
  leftTopPos: { x: 0, y: 0 }, // Левый верхний угол камеры в игровом мире.
  size: { x: 0, y: 0 }, // Размер камеры (по умолчанию, равен размеру холста)
  scale: 1,
};

ctx.translate用于大型游戏世界是否正确?就性能而言,将玩家始终保持在一个点上,(0, 0)还是(w/2, h/2)相对于他移动所有其他对象会更有效吗?

添加相机放大/缩小的问题。如果你这样做:

ctx.translate(-camera.leftTopPos.x, -camera.leftTopPos.y);
ctx.scale(camera.scale.x, camera.scale.y);

那么改变相机的大小就会出现问题,它会在某个地方移动。

我做了一个在jsfiddle上使用相机的例子。

wasd- 移动相机。 zx- 放大和缩小相机。

function p(s) { document.body.innerHTML += s + '<br>'; }

var w, h;
var camera = {
  leftTopPos: { x: 0, y: 0 },
  size: { x: 0, y: 0 },
  scale: 1,
};
var canvas = document.querySelector('canvas');
var can = canvas;
var context = canvas.getContext('2d');
var ctx = context;

function updateCameraSize() {
	camera.size = {
  	x: canvas.width,
    y: canvas.height,
  };
}

function setFullscreenSize() {
  w = canvas.width = window.innerWidth;
  h = canvas.height = window.innerHeight;
  updateCameraSize();
}

function makeAlwaysCanvasFullscreen() {
  setFullscreenSize();
  window.addEventListener('resize', setFullscreenSize);
}

function drawLine(x1, y1, x2, y2) {
	ctx.beginPath();
  ctx.moveTo(x1, y1);
  ctx.lineTo(x2, y2);
  ctx.stroke();
}

function drawGrid() {
  var cellSize = 100;
  var minX = -1000, maxX = 1000;
  var minY = -1000, maxY = 1000;
  for (var x = minX; x <= maxX; x += cellSize) {
    drawLine(x, minY, x, maxY);
  }
  for (var y = minY; y <= maxY; y += cellSize) {
    drawLine(minX, y, maxX, y);
  }
}

function drawAxises() {
  var minX = -1000, maxX = 1000;
  var minY = -1000, maxY = 1000;
  ctx.save();
  ctx.lineWidth = 5;
  ctx.strokeStyle = 'red';
  drawLine(0, 2 * minY, 0, 2 * maxY);
  ctx.strokeStyle = 'green';
  drawLine(2 * minX, 0, 2 * maxX, 0);
  ctx.restore();
}

function update() {
  var dir = { x: 0, y: 0 };
  var speed = 10;
  if (key.isPressed('a')) dir.x -= 1;
  if (key.isPressed('d')) dir.x += 1;
  if (key.isPressed('w')) dir.y -= 1;
  if (key.isPressed('s')) dir.y += 1;
  camera.leftTopPos.x += speed * dir.x;
  camera.leftTopPos.y += speed * dir.y;
}

function draw() {
	ctx.clearRect(0, 0, w, h);
  ctx.save();
  ctx.translate(-camera.leftTopPos.x, -camera.leftTopPos.y);
  ctx.scale(camera.scale, camera.scale);
  drawGrid();
  drawAxises();
  drawViewportRect();
  ctx.restore();
}

function drawViewportRect() {
  ctx.save();
  ctx.lineWidth = 10;
  ctx.strokeStyle = 'yellow';
  var pos = camera.leftTopPos, sz = camera.size;
  ctx.beginPath();
  ctx.rect(pos.x, pos.y, sz.x, sz.y);
  ctx.stroke();
  ctx.restore();
}

function main() {
  function go() {
  	update();
    draw();
    requestAnimationFrame(go);
  }
  requestAnimationFrame(go);
}

makeAlwaysCanvasFullscreen();
main();

key('z', () => {
	camera.scale += 0.1;
});
key('x', () => {
	camera.scale -= 0.1;
});
canvas {
  position: fixed;
  left: 0;
  top: 0;
  /* border: 1px solid black; */
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/keymaster/1.6.1/keymaster.min.js"></script>
<canvas></canvas>

html5
  • 1 个回答
  • 10 Views
Martin Hope
pank
Asked: 2020-06-03 05:28:25 +0000 UTC

如何用属性序列化表单?

  • 0

我正在用php开发一个网站。数据库有一个包含 id 和 name 列的表。在 php 中,会生成一个页面,格式如下:

<form>
  <select name="fruits">
    <option db-id="1">Apple</option>
    <option db-id="2">Orange</option>
    <option db-id="3">Apple</option>
  </select>
  <input type="submit">
</form>

现在我们需要以某种方式序列化这个表单,以便通过 Ajax 将它发送到服务器。在我使用这个功能之前:

$( "form" ).submit(function( event ) {
    let formData = $("form").serializeArray();
    // Отправка данных с помощью fetch или $.ajax
    event.preventDefault();
});

但是属性不是这样序列化的db-id。API 需要元素 id 来识别元素。

这个表格就是一个例子。真正的形式要大得多,编写自己的序列化程序有点贵。

也许除了 jquery 之外还有其他一些库可以让您将表单元素与属性一起序列化?还是有另一种方法来存储元素的 id - 不是在属性中,然后也只是将数据收集到一个对象中?

plnkr.co上的测试页面。

php
  • 1 个回答
  • 10 Views
Martin Hope
pank
Asked: 2020-05-29 04:06:45 +0000 UTC

将返回类型为 T 的函数转换为返回类型为字符串的函数

  • 1

试图编写一个函数来实现标题所说的功能:

template<class T>
function<string(int)> conv(function<T(int)> f) {
    return [&](int x) -> string {
        stringstream ss;
        ss << f(x);
        return ss.str();
    };
}

意念

clang 抛出此错误:

prog.cpp:28:3: error: no matching function for call to 'conv'
                conv(f1),
                ^~~~
prog.cpp:17:23: note: candidate template ignored: could not match 'function<type-parameter-0-0 (int)>' against 'int (*)(int)'
function<string(int)> conv(function<T(int)> f) {

或者这只是用宏完成的?

完整代码:

#include <iostream>
#include <functional>
#include <sstream>
#include <vector>
using namespace std;

int f1(int x) {
}

string f2(int x) {
}

long long f3(int x) {
}

template<class T>
function<string(int)> conv(function<T(int)> f) {
    return [&](int x) -> string {
        stringstream ss;
        ss << f(x);
        return ss.str();
    };
}

int main() {

    vector<function<string(int)>> funcs = {
        conv(f1),
    };

    return 0;
}
c++
  • 1 个回答
  • 10 Views
Martin Hope
pank
Asked: 2020-04-08 23:08:21 +0000 UTC

对切​​片的引用不同于对数组本身的引用

  • 0

我正在学习Go语言,我对此页面中的一个片段有疑问

修改代码以获取一些细节:

package main

import "fmt"
import "math/rand"

func main() {
    rand.Seed(1)
    primes := [6]int{2, 3, 5, 7, 11, 13}
    x := 0
    y := x + 1 + rand.Intn(2)
    fmt.Println(x, y)
    var s []int = primes[x:y]
    fmt.Println(s)
    fmt.Printf("%p\n", &primes)
    fmt.Printf("%p\n", &s)
    s[0] = 123
    fmt.Println(primes)
    fmt.Println(s)
}

结论:

0 2
[2 3]
0x104401c0
0x1040a150
[123 3 5 7 11 13]
[123 3]

首先我检查了是否可以制作动态切片。该代码显示了可能的情况。然后我决定找出切片是如何实现的。这里的问题是:为什么对数组的引用s和primes不同,而如果你改变数组的值s,然后改变和primes?在go中,事实证明,不是纯数组,而是带有附加信息的结构之类的东西?

PS 我能以某种方式找出go(&s - &primes- 不起作用)中链接之间的距离吗?

golang
  • 1 个回答
  • 10 Views
Martin Hope
pank
Asked: 2020-03-29 01:33:27 +0000 UTC

尝试输出 endl 时出错:'operator<<' 不匹配(操作数类型为 'A' 和 '<未解析的重载函数类型>')

  • 1

我想编写一个包装类,根据变量,将或不将日志输出到stdout和/或log.txt.

#include <iostream>
#include <fstream>
using namespace std;

struct A {
  bool use_log = 1, use_filelog = 0;
  ofstream log_file;
  void open() {
    use_filelog = 1;
    log_file.open("log.txt");
  }
};

template <class T> A &operator<<(A &a, T x) {
  if (a.use_log) {
    std::cout << x;
  }
  if (a.use_filelog) {
    a.log_file << x;
  }
  return a;
}

int main() {
  A a;
  a << "Hello, World!" << endl; // <= ERROR
}

当我尝试显示时出现错误endl。我不明白这是什么问题。

这个类可以用其他方式实现吗?

这是输出画布的开头gcc:

4.cpp: In function ‘int main()’:
4.cpp:26:24: error: no match for ‘operator<<’ (operand types are ‘A’ and ‘<unresolved overloaded function type>’)
   a << "Hello, World!" << endl;
                        ^
4.cpp:14:23: note: candidate: template<class T> A& operator<<(A&, T)
 template <class T> A &operator<<(A &a, T x) {
                       ^
4.cpp:14:23: note:   template argument deduction/substitution failed:
4.cpp:26:27: note:   couldn't deduce template parameter ‘T’
   a << "Hello, World!" << endl;
                           ^
In file included from /usr/include/c++/5/iostream:39:0,
                 from 4.cpp:1:
/usr/include/c++/5/ostream:628:5: note: candidate: template<class _CharT, class _Traits, class _Tp> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&)
     operator<<(basic_ostream<_CharT, _Traits>&& __os, const _Tp& __x)

但是来自clang:

prog.cpp:26:27: error: reference to overloaded function could not be resolved; did you mean to call it?
  a << "Hello, World!" << endl;
                          ^~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/ostream:590:5: note: possible target for call
    endl(basic_ostream<_CharT, _Traits>& __os)
    ^
prog.cpp:14:23: note: candidate template ignored: couldn't infer template argument 'T'
template <class T> A &operator<<(A &a, T x) {
c++
  • 1 个回答
  • 10 Views
Martin Hope
pank
Asked: 2020-03-16 16:18:48 +0000 UTC

无法从 JavaScript 访问方法:ScriptException:TypeError:note.getTitle 不是函数

  • 1

我在这里找到了一个在Java 中使用脚本的示例。我创建了我的类,创建了一个实例,将它放入,运行它的方法并得到一个错误:NoteenginegetTitle

Exception in thread "main" javax.script.ScriptException: TypeError:
note.getTitle is not a function in <eval> at line number 1

我以与链接中的示例相同的方式完成了所有操作。可能是什么问题呢?

使用File它的代码可以工作,但对于我的班级Note则不行。

如果你这样写:engine.eval("print(note.title)");,那么输出将是undefined。

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.io.File;

public class Arrays {

    class Note {
        public String title, text;
        Note(String title, String text) {
            this.title = title;
            this.text = text;
        }
        public String getTitle() { return title; }
    }

    void run() throws Exception {
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("JavaScript");

        Note note = new Note("title", "text");
        engine.put("note", note);
        engine.eval("print(note.getTitle())");

        File f = new File("a.txt");
        engine.put("f", f);
        engine.eval("print(f.getAbsolutePath())");
    }

    public static void main(String[] args) throws Exception {
        Arrays main = new Arrays();
        main.run();
    }
}
java
  • 1 个回答
  • 10 Views
Martin Hope
pank
Asked: 2020-03-15 18:21:58 +0000 UTC

为什么 ostream 的 << 运算符没有为容器超载?

  • 9

为什么 for 运算符不会为, ,之类的容器<<超载?ostreamvectorsetmap

<<如果运算符重载for存在问题ostream,那么为什么不添加一个函数printor print_container,它可以输出容器。

出于好奇,我问得更多,因为我必须自己实现这样的小事。而且,在许多其他语言中显示容器并不困难。

c++
  • 4 个回答
  • 10 Views
Martin Hope
pank
Asked: 2020-03-14 16:36:44 +0000 UTC

在什么情况下,完全在头文件中实现的类会导致错误?

  • 0

我有好几次遇到这样的情况,当一个类在头文件中完全实现时,在执行过程中导致错误。

但是一旦类被分成两个文件.h,.cpp错误就会立即消失。

试图专门重现这样的错误,但到目前为止还没有奏效。

什么会导致此类错误?

c++
  • 1 个回答
  • 10 Views
Martin Hope
pank
Asked: 2020-03-11 19:03:05 +0000 UTC

使用 typedef 实例化模板类

  • 1

有一个模板类A,我想用它制作两个具体的类:B和C

#include <iostream>
using namespace std;

template<const char* s = "hello">
class A {
public:
    void foo();
};

template<const char* s>
void A<s>::foo() {
    cout << s;
}

typedef A<" world"> B;

class C : public A<"!\n"> {};

int main() {
    A<"hello"> a;
    B b;
    C c;
    a.foo();
    b.foo();
    c.foo();
    return 0;
}

但我得到一个错误:

prog.cpp:15:19: error: ‘" world"’ is not a valid template argument for type ‘const char*’ because string literals can never be used in this context
 typedef A<" world"> B;
                   ^
prog.cpp:17:25: error: ‘"!\012"’ is not a valid template argument for type ‘const char*’ because string literals can never be used in this context
 class C : public A<"!\n"> {};
                         ^
prog.cpp: In function ‘int main()’:
prog.cpp:20:11: error: ‘"hello"’ is not a valid template argument for type ‘const char*’ because string literals can never be used in this context
  A<"hello"> a;
           ^
prog.cpp:23:4: error: request for member ‘foo’ in ‘a’, which is of non-class type ‘int’
  a.foo();
    ^~~
prog.cpp:24:4: error: request for member ‘foo’ in ‘b’, which is of non-class type ‘B {aka int}’
  b.foo();
    ^~~
prog.cpp:25:4: error: ‘class C’ has no member named ‘foo’
  c.foo();
    ^~~

ideone 上的代码。

如果模板中的 yA是整数而不是字符串,则代码可以正常工作。

c++
  • 1 个回答
  • 10 Views
Martin Hope
pank
Asked: 2020-02-28 01:18:25 +0000 UTC

使用 clang-format 自动格式化复杂代码

  • 2

我用clang-format它来自动格式化代码,在大多数情况下它可以应对爆炸,但有一段代码没有按照我们的意愿进行格式化。

从示例到库的一段代码(github 上的文件):

int main(int argc, char* argv[])
{
    options.add_options()
      ("a,apple", "an apple", cxxopts::value<bool>(apple))
      ("b,bob", "Bob")
      ("f,file", "File", cxxopts::value<std::vector<std::string>>(), "FILE")
      ("i,input", "Input", cxxopts::value<std::string>())
      ("o,output", "Output file", cxxopts::value<std::string>()
          ->default_value("a.out")->implicit_value("b.def"), "BIN")
      ("positional",
        "Positional arguments: these are the arguments that are entered "
        "without an option", cxxopts::value<std::vector<std::string>>())
      ("long-description",
        "thisisareallylongwordthattakesupthewholelineandcannotbebrokenataspace")
      ("help", "Print help")
      ("int", "An integer", cxxopts::value<int>(), "N")
      ("option_that_is_too_long_for_the_help", "A very long option")
    ;
}

变成不可读的东西:

int main(int argc, char *argv[]) {
  options.add_options()("a,apple", "an apple",
                        cxxopts::value<bool>(apple))("b,bob", "Bob")(
      "f,file", "File", cxxopts::value<std::vector<std::string>>(),
      "FILE")("i,input", "Input", cxxopts::value<std::string>())(
      "o,output", "Output file",
      cxxopts::value<std::string>()->default_value("a.out")->implicit_value(
          "b.def"),
      "BIN")("positional",
             "Positional arguments: these are the arguments that are entered "
             "without an option",
             cxxopts::value<std::vector<std::string>>())(
      "long-description",
      "thisisareallylongwordthattakesupthewholelineandcannotbebrokenataspace")(
      "help", "Print help")("int", "An integer", cxxopts::value<int>(), "N")(
      "option_that_is_too_long_for_the_help", "A very long option");
}

.clang-format:

BasedOnStyle: LLVM
IndentWidth: 2
---
Language: Cpp
Standard: Cpp11

这可以以某种方式解决吗?

c++
  • 1 个回答
  • 10 Views
Martin Hope
pank
Asked: 2020-02-22 02:41:04 +0000 UTC

使用 Makefile 只编译选定的文件

  • 0

我们需要一个只编译SRCS.

例如,有如下文件结构:

test/
    a.cpp
    b.cpp
    c.cpp
    d.cpp
    ...
    Makefile

生成文件:

SRCS = a.cpp c.cpp ...
OBJS = $(SRCS:.cpp=.o)

???

接下来要写什么,以便每个文件SRCS从OBJS. 不是所有.cpp文件,而是仅选定的文件。

变量SRCS可能随时间变化。这可能不仅对于将.cpp文件编译成目标文件是必要的.o,而且对于其他任务也是必要的。

makefile
  • 1 个回答
  • 10 Views
Martin Hope
pank
Asked: 2020-01-30 01:52:44 +0000 UTC

组织具有库依赖项的项目[关闭]

  • 2
关闭。这个问题需要具体说明。目前不接受回复。

你想改进这个问题吗? 重新设计问题,使其只关注一个问题。

5 年前关闭。

改进问题

这个问题可能有点含糊。因此,我将尝试更详细地描述它并将其分解为更小的问题。

例如,我想编写一个需要多个库的程序。将这些库添加到项目中的最佳方式是什么?

有些库不在存储库中,您必须从某个地方的站点下载它们(?)解压缩它们,以某种方式(?)添加这些库的包含和源代码。

在什么情况下创建.so/.dll文件,在什么情况下可以立即将所有文件组装成一个可执行文件.cpp?

我还想让这个程序跨平台,如果我从Linux上的存储库安装库,那么在其他平台上呢?

还是这些问题就没有正确的、通用的方法,照它做?

到目前为止,我只看到最适合自己的解决方案cmake。

找到一个可以自己加载必要的库的工具会很酷 :) 比如 innpm或gradle.

c++
  • 1 个回答
  • 10 Views
Martin Hope
pank
Asked: 2020-01-24 21:34:42 +0000 UTC

跨平台方式获取可存放应用程序文件的文件夹

  • 1

例如,在Linux/home/user_name/.app_name上,该文件夹为,而在Windows上,该文件夹为AppData。

如何跨平台获取可以创建文件夹.app_name和存放应用程序文件的目录路径?

c++
  • 3 个回答
  • 10 Views
Martin Hope
pank
Asked: 2020-01-06 19:48:07 +0000 UTC

使用 try/catch 确定程序在内存中的位置?

  • 0

我把指针移到内存的开头p = 0,增加它,记住(noerr)没有错误发生的时刻。然后我寻找错误再次出现的时刻(err)。[noerr; err)原来是程序在内存区间。但是代码在第一次迭代时就已经崩溃了。

Ошибка сегментирования (сделан дамп памяти)

编码:

#include <iostream>
using namespace std;

int main()
{
  char *p = 0, *noerr = 0, *err = 0;
  while (1) {
    try {
      char c = *p;
      if (!noerr) {
          noerr = p;
          cout << "noerr: " << (int)noerr << endl;
      }
    } catch (...) {
      p++;
      if (noerr) {
          err = p;
          cout << "err: " << (int)err << endl;
          break;
      }
    }
  }
}

为什么try/catch它不捕获错误?我怎样才能修复该程序,使其按我的预期工作?

操作系统:Linux。

解决方案

main.cpp:

#include <iostream>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <fstream>
using namespace std;

int main();

char *begin_ptr;

void find_begin() {
  char *p = (char*) main;
  while (1) {
    begin_ptr = p;
    char c = *(--p);
  }
}

void find_end() {
  char *p = (char*) main;
  while (1) {
    ofstream f("end.txt");
    f << (int) p;
    f.close();
    char c = *(++p);
  }
}

void sig_handler(int signo) {
  ofstream f("begin.txt");
  f << (int) begin_ptr;
  f.close();
  cout << "Signal " << signo << endl;
  cout << "begin_ptr: " << (int) begin_ptr << endl;
  cout << "dist from begin to main: " << ((char*)main - begin_ptr) << endl;
  find_end();
  exit(0);
}

void HandlerRun () {
  printf("Sig Handle Initialized!\n");
  signal(SIGSEGV, sig_handler);
  signal(SIGSTOP, sig_handler);
  signal(SIGTERM, sig_handler);
  // signal(SIGKILL, sig_handler);
  signal(SIGABRT, sig_handler);
  signal(SIGINT , sig_handler);
}

int main() {
  HandlerRun();
  ofstream f("main.txt");
  f << (int) main;
  f.close();
  cout << "main: " << (int) main << endl;
  find_begin();
}

main.sh:

./main > /dev/null
beg=$(cat begin.txt)
end=$(cat end.txt)
echo begin: $beg
echo end: $end
echo end - begin: $(echo $end - $beg | bc)

输出示例:

begin: 134512640
end: 134529023
end - begin: 16383
c++
  • 1 个回答
  • 10 Views
Martin Hope
pank
Asked: 2020-12-17 00:21:39 +0000 UTC

什么是 C++ 中的标准布局,为什么需要它?

  • 1

我用英文读了它,但我无法理解。

c++
  • 1 个回答
  • 10 Views
Martin Hope
pank
Asked: 2020-12-17 00:15:15 +0000 UTC

常量 x 和 &xx 有什么区别?

  • 5

常量 x 和 &xx 有什么区别?

#include <iostream>
using namespace std;

int main() {
    const int x = 2;
    const int &xx = 3;
    cout << x << endl;
    cout << xx << endl;
    return 0;
}

为什么需要它&?

c++
  • 3 个回答
  • 10 Views
Martin Hope
pank
Asked: 2020-12-10 04:05:33 +0000 UTC

带有变量模板的 I/O 函数

  • 2

如何read使用print变体模板正确实现功能?

read(a1, a2, ..., an); // тоже, что и cin >> a1 >> a2 >> ... >> an;
print(a1, a2, ..., an); // тоже, что и cout << a1 << " " << a2 << " " << ... << " " << an;
c++
  • 2 个回答
  • 10 Views
Martin Hope
pank
Asked: 2020-11-12 03:50:30 +0000 UTC

如何从模块继承?

  • 0

档案m1.py:

x = 1
def y():
    return 2
# ... Много переменных и функций ...

如何使类Foo包含模块包含的所有内容m1?

试过这样的:

档案m2.py:

import m1

class Foo(m1):
    pass

但是得到一个错误:

TypeError: module.__init__() takes at most 2 arguments (3 given)
python
  • 2 个回答
  • 10 Views
Martin Hope
pank
Asked: 2020-11-06 19:56:23 +0000 UTC

是否可以在 C++ 中创建数据类?

  • 2

在该语言中,Kotlin您可以创建简单的类data class:

data class User(val name: String, val age: Int)

在这种情况下,对于对象,代码会自动生成:

  1. 翻译成data class字符串:"User(name=John, age=42)".
  2. 比较与
  3. 复制日期类。

C++是否可以使用宏和/或变量模板做类似的事情?

这应该如何工作的可能示例:

DataClass(Data, string, name, int, age);
// ...
Data d = { "Mike", 33 };
d.name = "John";
d.age = 42;
cout << d; // Data(name=John, age=42)
c++
  • 2 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5