我有类似的东西:
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编译.
可能重复:(
如何)我可以计算枚举中的项目?
有没有办法获得枚举中的常量数?
例如:
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
这是从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) 当我通过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) 使用以下代码获取驱动器的名称:
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) 有没有办法检测p和d指向的对象是否属于不同的类型?(p指向int,d指向int数组):
int* p = new int();
int* d = new int[20];
Run Code Online (Sandbox Code Playgroud) 在这个简短的代码中:
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) 在Unity的MonoDevelop中,我正在使用C#来开发我的"伟大"游戏.我在那里使用秒表,并且很有趣,即使在这里列出了这个类,也没有重启方法:http:
//msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx# Y292
我错过了什么吗?
clear 函数是 std::map 的时间复杂度是多少?
我说它是 O(1) 对吗?