小编Fac*_*con的帖子

你如何声明一个const数组的函数指针?

首先,我有这样的功能.

void func1();
void func2();
void func3();
Run Code Online (Sandbox Code Playgroud)

然后我为数组创建我的typedef:

void (*FP)();
Run Code Online (Sandbox Code Playgroud)

如果我写一个正常的函数指针数组,它应该是这样的:

FP array[3] = {&func1, &func2, &func3};
Run Code Online (Sandbox Code Playgroud)

我想使它成为一个常量数组,在"FP"之前使用const,但我有这个错误消息:

错误:无法将'void(*)()'转换为'void(*const)()'inialization

PD:抱歉我的英语不好.

编辑:

XH

typedef void (*FP)();

class x
{
 private:
  int number;
  void func1();
  void func2();
  void func3();
  static const FP array[3];
}
Run Code Online (Sandbox Code Playgroud)

x.cpp

const FP x::array[3] = {&x::func1, &x::func2, &x::func3};
Run Code Online (Sandbox Code Playgroud)

我的代码更大,更复杂,这是一个总结

c++ arrays function-pointers

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

中断如何在Intel 8080上运行?

中断如何在Intel 8080上运行?我搜索了谷歌和英特尔的官方文档(197X),我发现只有一点关于此的描述.我需要一个关于它的详细解释,来模拟这个CPU.

interrupt intel-8080

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

数组初始化中的未知错误:非整数类型`const unsigned char [256]'的静态数据成员的类内初始化无效

我试图制作一个Intel 8080 CPU仿真器(然后我想仿效使用它的Space Invaders).

我编写这个CPU几乎完全实现(感谢MAME和痒感项目(大部分);)),除了undocument指令(0x08时,0x10的,为0x18,0x20的,0×28,为0x30,0x38,0x0CB,0x0D9,0x0DD,0x0ED,0x0FD).

编译时我只有问题,我不知道为什么.

这是代码:

static const unsigned char cycles_table[256] =
{
    /*                       8080's Cycles Table                         */
    /*     0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F */
    /*0*/  4, 10,  7,  5,  5,  5,  7,  4,  0, 10,  7,  5,  5,  5,  7,  4,
    /*1*/  0, 10,  7,  5,  5,  5,  7,  4,  0, 10,  7,  5,  5,  5,  7,  4,
    /*2*/  0, 10, 16,  5,  5,  5,  7,  4, …
Run Code Online (Sandbox Code Playgroud)

c++ arrays gcc syntax-error

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

将readline连接到Rust

我尝试在rust中进行本教程,到目前为止,我在将C库连接到Rust中时遇到很多问题。

C等效代码:

#include <stdio.h>
#include <stdlib.h>

#include <editline/readline.h>
#include <editline/history.h>

int main(int argc, char** argv) {

  /* Print Version and Exit Information */
  puts("Lispy Version 0.0.0.0.1");
  puts("Press Ctrl+c to Exit\n");

  /* In a never ending loop */
  while (1) {

    /* Output our prompt and get input */
    char* input = readline("lispy> ");

    /* Add input to history */
    add_history(input);

    /* Echo input back to user */    
    printf("No you're a %s\n", input);

    /* Free retrived input */
    free(input); …
Run Code Online (Sandbox Code Playgroud)

readline rust

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

如何在Python中序列化哈希对象

如何序列化哈希对象?我正在使用shelve来存储大量对象。

等级制度:

- user
    - client
    - friend
Run Code Online (Sandbox Code Playgroud)

用户.py:

import time
import hashlib
from localfile import localfile

class user(object):
    _id = 0
    _ip = "127.0.0.1"
    _nick = "Unnamed"
    _files = {}
    def __init__(self, ip="127.0.0.1", nick="Unnamed"):
        self._id = hashlib.sha1(str(time.time()))
        self._ip = ip
        self._nick = nick
    def add_file(self, localfile):
        self._files[localfile.hash] = localfile
    def delete_file(self, localfile):
        del self._files[localfile.hash]

if __name__ == "__main__":
    pass
Run Code Online (Sandbox Code Playgroud)

客户端.py:

from user import user
from friend import friend

class client(user):
    _friends = []
    def __init__(self, ip="127.0.0.1", nick="Unnamed"): …
Run Code Online (Sandbox Code Playgroud)

python hash serialization shelve

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

从byte []到String的精确转换

数组byte []包含照片的完美逐字节副本,当我尝试将byte []转换为String并使用它写入文件时,它会失败.

我需要转换为字符串以便稍后通过套接字发送它.

我的每个连接的处理程序都有一个Socket(sock),PrintWriter(out)和BufferedReader(in),然后我将Socket与PrintWriter和BufferedReader相关联.有了这个,我发送和接收字符串out.println和in.readLine.

我怎样才能解决这个问题?

测试代码:

// getPhoto() returns byte[]
String photo = new String(getPhoto());

// Create file
DataOutputStream os = new DataOutputStream(new FileOutputStream("out1.jpg"));
// This makes imperfect copy of the photo
os.writeBytes(photo);

//This works perfectly basically it copies the image through byte[]
//os.write(getPhoto());

// Close the output stream
os.close();
Run Code Online (Sandbox Code Playgroud)

java string bytearray file

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