小编Sco*_*ott的帖子

在全球范围内实例化(C++)

我使用下面的代码得到以下错误.

expected constructor, destructor, or type conversion before '=' token
Run Code Online (Sandbox Code Playgroud)

-

#include <string>
#include <map>

class Foo {

};

std::map<std::string, Foo> map;
map["bar"] = Foo();

int main()
{

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

c++ global-variables instantiation

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

库重新定义了NULL

我正在使用重新定义NULL的库.它导致我的程序的其他部分出现一些问题.我不知道我能做些什么.任何的想法?我在C++程序,该库在Ç.

#ifdef NULL
#undef NULL
#endif

/**
 * NULL define.
 */
#define NULL    ((void *) 0)
Run Code Online (Sandbox Code Playgroud)

哦,它会产生这些错误:

Generic.h:67: error: default argument for parameter of type 'LCD::LCDBase*' has type 'void*'
Generic.cpp: In constructor 'LCD::Generic::Generic(std::string, Json::Value*, int, LCD::LCDBase*)':
Generic.cpp:44: error: invalid conversion from 'void*' to 'QObject*'
Generic.cpp:44: error:   initializing argument 2 of 'LCD::LCDWrapper::LCDWrapper(LCD::LCDInterface*, QObject*)'
Generic.cpp: In member function 'void LCD::Generic::BuildLayouts()':
Generic.cpp:202: error: invalid conversion from 'void*' to 'LCD::Widget*'
Generic.cpp: In member function 'void LCD::Generic::AddWidget(std::string, unsigned int, unsigned int, std::string)':
Generic.cpp:459: …
Run Code Online (Sandbox Code Playgroud)

c c++ null undefined c-preprocessor

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

我该怎么做才能跟踪这个错误?

我有一个char指针出现的错误NULL.我一直在使用该程序的gdb,观察内存地址的读/写,并逐步完成指令,但到目前为止,这个错误让我感到困惑.我已经运行了valgrind,唯一出现的是崩溃时的读取(strcmp).我还能做些什么来追踪这个?

c linux debugging

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

计算滑动平均值

我甚至不确定滑动平均值是多少,但是有人告诉我这对我正在研究的东西有帮助.

我有一张随机值表 - table[n] = random(100) / 100

我需要填充table2他们的滑动平均值.

我认为这是术语.如果它没有意义,请告诉我.

javascript c python sliding

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

帮我调试一下 - 从'const char*'到'char*'的无效转换

我根本不明白为什么会出现这个错误.

Widget.cpp: In constructor 'Widget::Widget(Generic, char*, int, int, int, QObject*)':
Widget.cpp:13: error: invalid conversion from 'const char*' to 'char*'
Run Code Online (Sandbox Code Playgroud)

就Widget的构造函数而言,我没有任何'const char*'.

class Widget: public QObject {
    Q_OBJECT
    Q_PROPERTY(char *col READ getCol WRITE setCol)
    Q_PROPERTY(char *row READ getRow WRITE setRow)
    Generic visitor;
    char *_name;
    char *_widget_base;
    int _row;
    int _col;
    int _type;
    public:
    Widget(Generic visitor, char *name, int row, int col, int type, QObject *parent);
    char* widgetBase() const;
    QString getCol() const;
    void setCol(const QString &col);
    QString getRow() const;
    void setRow(const QString …
Run Code Online (Sandbox Code Playgroud)

c++ const

0
推荐指数
1
解决办法
2644
查看次数

'::'标记之前的预期构造函数,析构函数或类型转换

编译文件时出现以下错误.

//Error
PluginDiskstats.cpp:107: error: expected constructor, destructor, or type conversion before '::' token
scons: *** [PluginDiskstats.o] Error 1



// destructor
~PluginDiskstats::PluginDiskstats() // line 107
{
    if (stream != NULL) {
        fclose(stream);
        stream = NULL;
    }
    hash_destroy(&DISKSTATS);
}



// header file

#ifndef __PLUGIN_DISKSTATS_H__
#define __PLUGIN_DISKSTATS_H__

#include <QObject>
#include "Hash.h"

class PluginDiskstats : public QObject {
    Q_OBJECT
    HASH DISKSTATS;
    FILE *stream;
    int ParseDiskstats();

    public:
    PluginDiskstats();
    ~PluginDiskstats();

    public slots:
    double Diskstats(QString arg1, QString arg2, double arg3);
};

#endif
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
993
查看次数

常见问题

我现在应该得到这个,但我还没有得到它.问题是operator =的参数可能是非const,但是它会破坏std :: vector :: push_back,因为它使项目为const,所以operator =必须接受一个const对象.好吧,我不确定我应该如何修改这个像这样工作的对象.

#include <vector>
#include <map>
#include <iostream>

using namespace std;

int font[] = {0, 31, 0, 31, 0, 31, 0, 31};

class Foo {
    int size_;
    std::map<int, int> chars_;
    public:
    Foo(int *font, int size);
    unsigned int Size() const { return size_; }
    void Add(int ch);
    bool operator==(const Foo &rhv) const;
    int &operator[](int i);
    int const operator[](int i);
    Foo operator=(const Foo &rhv);
};

Foo::Foo(int *font, int size) {
    for(int i = 0; i < size; …
Run Code Online (Sandbox Code Playgroud)

c++ const

0
推荐指数
1
解决办法
681
查看次数

一些Python代码的一些帮助

谁能告诉我为什么num_chars和num_rows必须相同?

from ctypes import *

num_chars = 8
num_rows = 8
num_cols = 6

buffer = create_string_buffer (num_chars*num_rows*num_cols+num_chars)

for char in range(num_chars):
        for row in range(num_rows):
                for col in range(num_cols):
                        if char == num_chars-1 and col == num_cols-1:
                                buffer[row*num_rows*num_cols+char*num_cols+col+row] = '|'
                                buffer[row*num_rows*num_cols+char*num_cols+col+row+1] = '\n'
                        elif col == num_cols-1:
                                buffer[row*num_rows*num_cols+char*num_cols+col+row] = '|'
                        else:
                                buffer[row*num_rows*num_cols+char*num_cols+col+row] = ('.', '*')[char>row]

print buffer.value
Run Code Online (Sandbox Code Playgroud)

输出

.....|*****|*****|*****|*****|*****|*****|*****|
.....|.....|*****|*****|*****|*****|*****|*****|
.....|.....|.....|*****|*****|*****|*****|*****|
.....|.....|.....|.....|*****|*****|*****|*****|
.....|.....|.....|.....|.....|*****|*****|*****|
.....|.....|.....|.....|.....|.....|*****|*****|
.....|.....|.....|.....|.....|.....|.....|*****|
.....|.....|.....|.....|.....|.....|.....|.....|
Run Code Online (Sandbox Code Playgroud)

现在将num_chars更改为15.

.....|*****|*****|*****|*****|*****|*****|*****|*****|*****|*****|*****|*****|*****|*****|
*****|*****|*****|*****|*****|*****|*****|*****|
*****|*****|*****|*****|*****|*****|*****|*****|
*****|*****|*****|*****|*****|*****|*****|*****|
*****|*****|*****|*****|*****|*****|*****|*****|
*****|*****|*****|*****|*****|*****|*****|*****|
*****|*****|*****|*****|*****|*****|*****|*****|
.....|*****|*****|*****|*****|*****|*****|*****|
Run Code Online (Sandbox Code Playgroud)

python ctypes

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