相关疑难解决方法(0)

带有附加可选模板参数的标准库容器?

在文章中多次阅读索赔 - 我想将此问题添加到Stackoverflow,并询问社区 - 以下代码是否可移植?

template<template<typename T, typename Alloc> class C>
void f() {
  /* some code goes here ... */
}

int main() {
  f<std::vector>();
}
Run Code Online (Sandbox Code Playgroud)

供应的实施是否std::vector真的允许有两个众所周知的额外的,默认的模板参数?这会使上面的代码格式错误,因为它假设有两个模板参数.见最后一段在这篇文章中对这种要求的一个例子.

c++ parameters standards templates stl

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

C++,删除类头中的#include <vector>或#include <string>

我想删除,如果可能的话,从我的类头文件中包含<vector>和<string>.string和vector都是头文件中声明的函数的返回类型.

我希望我可以这样做:

namespace std {
    template <class T>
    class vector;
}
Run Code Online (Sandbox Code Playgroud)

并且,在标头中声明向量并将其包含在源文件中.

是否有参考文献,包括您必须在标题中包含的情况,以及您可以将包含纳入源文件的情况?

c++ templates include

4
推荐指数
4
解决办法
3563
查看次数

如何声明彼此引用的类?

自从我完成C++以来已经很长时间了,我遇到了相互引用类的麻烦.

现在我有类似的东西:

class a
{
  public:
    a();
    bool skeletonfunc(b temp);
};
Run Code Online (Sandbox Code Playgroud)

BH

class b
{
  public:
    b();
    bool skeletonfunc(a temp);
};
Run Code Online (Sandbox Code Playgroud)

由于每个人都需要引用另一个,我发现我不能在顶部做彼此的#include,或者我最后在包含的奇怪的循环中.

那么,如何让这个a可以使用b并且没有发生周期性的#include问题反之亦然?

谢谢!

c++ reference class include

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

不完整类型 Qt 的使用无效

我有一个小问题:

查找对话框.h

#ifndef FINDDIALOG_H
#define FINDDIALOG_H

class QDialog;
class QWidget;
class QLineEdit;
class QPushButton;
class QCheckBox;
class QLabel;

class FindDialog : public QDialog
{
    Q_OBJECT


public:
    FindDialog(QWidget *parent);

private slots:
    void findClicked();
    void enableFindButton(const QString &text);

signals :
    void findNext(const QString &str, Qt::CaseSensitivity cs);
    void findPrev(const QString &str, Qt::CaseSensitivity cs);

private:
    QLabel *findLabel;
    QLineEdit *textEdit;
    QCheckBox *caseCheckBox;
    QCheckBox *backwCheckBox;
    QPushButton *findButton;
    QPushButton *closeButton;

};

#endif // FINDDIALOG_H
Run Code Online (Sandbox Code Playgroud)

查找对话框

#include <QtWidgets>
#include "finddialog.h"


FindDialog::FindDialog(QWidget *parent) : QDialog(parent)
{
    QPushButton *button = …
Run Code Online (Sandbox Code Playgroud)

c++ linker qt base-class

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

"类名"必须是先前定义的类或结构

请看这个简单的课程:

class TernaryPolynomial;
class IntegerPolynomial;

class DenseTernaryPolynomial:public IntegerPolynomial,public TernaryPolynomial
{
 public:
 DenseTernaryPolynomial();
static DenseTernaryPolynomial generateRandom(int,int,int);
};
Run Code Online (Sandbox Code Playgroud)

你能解释一下,为什么编译器会抱怨TernaryPolynomial必须是以前定义的类或结构?我认为它根本不应该关心,因为我提出了该类的前瞻声明.这是TernaryPolynomial类

class Polynomial;
class IntegerPolynomial;

class TernaryPolynomial:public Polynomial
{
 public:
 TernaryPolynomial();
 virtual ~TernaryPolynomial();
 virtual IntegerPolynomial toIntegerPolynomial() = 0;
 };
Run Code Online (Sandbox Code Playgroud)

c++ inheritance

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