小编sma*_*llB的帖子

枚举有问题

我有类似的东西:

enum Direction{Forward,Backward};

template<Direction dir = Forward>
class X
{
private:

    Direction my_direction_;
public:

    void set_direction(Direction dir)//here I'm getting an error
    {
        my_direction_ = dir;
    }

};
Run Code Online (Sandbox Code Playgroud)

错误:'Direction dir'的声明有
什么理由?顺便说一下,它确实用VS2010编译.

c++

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

枚举中的"常量"数

可能重复:(
如何)我可以计算枚举中的项目?

有没有办法获得枚举中的常量数?
例如:

enum C{id,value};
Run Code Online (Sandbox Code Playgroud)

以后这将返回2:

//pseudo code
get<C>::value 
Run Code Online (Sandbox Code Playgroud)

而且,是否可以通过[] optor访问这些常量?喜欢ie:
C [0]会返回id

c++

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

为什么我的视图没有显示标题?

这是从Qt教程复制的类:

class Window : public QWidget
{
    Q_OBJECT

public:
    Window();

    void setSourceModel();

private slots:
    void filterRegExpChanged();
    void filterColumnChanged();
    void sortChanged();
    void addMail();

private:
    QSortFilterProxyModel *proxyModel;
    QStandardItemModel *model;

    QGroupBox *sourceGroupBox;
    QGroupBox *proxyGroupBox;

    QTreeView *sourceView;
    QTreeView *proxyView;
    QCheckBox *filterCaseSensitivityCheckBox;
    QCheckBox *sortCaseSensitivityCheckBox;
    QLabel *filterPatternLabel;
    QLabel *filterSyntaxLabel;
    QLabel *filterColumnLabel;
    QLineEdit *filterPatternLineEdit;
    QComboBox *filterSyntaxComboBox;
    QComboBox *filterColumnComboBox;
    QPushButton* button;
};  
Run Code Online (Sandbox Code Playgroud)

这是一个ctor的定义:

Window::Window()
{
    model = new QStandardItemModel(this);  
//HEADERS ARE NOT DISPLAYED EVEN THOUGH I'M SETTING THEM HERE
    model->setHeaderData(0, Qt::Horizontal, QObject::tr("Subject"));
    model->setHeaderData(1, Qt::Horizontal, QObject::tr("Sender"));
    model->setHeaderData(2, Qt::Horizontal, QObject::tr("Date")); …
Run Code Online (Sandbox Code Playgroud)

c++ qt

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

我不需要dot和dotdot

当我通过QDir :: entryInfoList列出条目时,我得到两个额外的条目,一个带点,第二个带两个点.如果我设置QDir :: NoDot和QDir :: NoDotDot,则不会列出任何内容.我只需要传递给QDir的文件夹的内容,没有别的.

 QFileInfo fi(model_->filePath(e));
        auto file_path = fi.absoluteFilePath();
        auto lyst = QDir(fi.absoluteFilePath()).entryInfoList(/*QDir::NoDotAndDotDot makes lyst empty*/);
        foreach (QFileInfo info , lyst)
        {
            qDebug() << info.absoluteFilePath();
        }
Run Code Online (Sandbox Code Playgroud)

c++ qt

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

使用GetLogicalDriveStrings()获取未知数据

使用以下代码获取驱动器的名称:

const DWORD buffer_length = sizeof(DWORD)*CHAR_BIT;
WCHAR buffer[buffer_length] = {0};
GetLogicalDriveStrings(buffer_length,buffer);
std::set<wchar_t> drives_letters;
for(auto e : buffer)
{
    drives_letters.insert(e);
}  
Run Code Online (Sandbox Code Playgroud)

因此我得到了以下输出(循环遍历drives_letters):

: //what on earth is this?  
C 
D 
E 
F 
G 
I 
\ //and what on earth is this?  
Run Code Online (Sandbox Code Playgroud)

c++ winapi

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

检测我指的是什么

有没有办法检测p和d指向的对象是否属于不同的类型?(p指向int,d指向int数组):

int* p = new int();
int* d = new int[20];  
Run Code Online (Sandbox Code Playgroud)

c++

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

指向成员函数的指针 - 不想工作

在这个简短的代码中:

class X
{
private:
    class Y
    {

    public:
        typedef void (X::* ptr_to_mem)();
        Y(X* parent,ptr_to_mem ptr):parent_(parent),ptr_(ptr)
        {}
        void run()
        {
            parent_->*ptr_();//at this line I'm getting an error
        }
    private:
        X* parent_;
        ptr_to_mem ptr_;
    };

public:
    void some_fnc()
    {
        cout << "some_fnc";
    }

    void another()
    {
        Y y_(this,&X::some_fnc);
        y_.run();
    }

};
Run Code Online (Sandbox Code Playgroud)

错误:

error: must use '.*' or '->*' to call pointer-to-member function in '((X::Y*)this)->X::Y::ptr_ (...)', e.g. '(... ->* ((X::Y*)this)->X::Y::ptr_) (...)'
Run Code Online (Sandbox Code Playgroud)

c++ pointers

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

不希望我的对话框上有关闭按钮

可以从QDialog中删除关闭按钮吗?

qt

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

秒表没有重启

在Unity的MonoDevelop中,我正在使用C#来开发我的"伟大"游戏.我在那里使用秒表,并且很有趣,即使在这里列出了这个类,也没有重启方法:http:
//msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx# Y292

我错过了什么吗?

.net c# stopwatch .net-4.0 c#-4.0

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

根据大 O,清晰函数是 std::map 的时间复杂度是多少?

clear 函数是 std::map 的时间复杂度是多少?
我说它是 O(1) 对吗?

c++ map time-complexity

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

标签 统计

c++ ×8

qt ×3

.net ×1

.net-4.0 ×1

c# ×1

c#-4.0 ×1

map ×1

pointers ×1

stopwatch ×1

time-complexity ×1

winapi ×1