我正在嘗試編寫一個小應用程序,並且遇到了使用auto_ptr的編譯時錯誤。ISO C++禁止聲明沒有類型的'auto_ptr'
我最初厭倦用我創建的類創建一個智能指針,但是如果我嘗試創建一個類型爲int的智能指針,就會出現同樣的錯誤,所以我必須做其他事情。我按照給出的例子here.。
我有一種感覺,這個答案會導致我拍我自己。
我在這個文件的底部聲明瞭智能指針。
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <memory.h>
#include <QMainWindow>
#include "dose_calac.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
/*
Some QT stuff here, removed for clarity/size...
*/
private:
Ui::MainWindow *ui;
/*
Object for storage of data and calculation of DOSE index score.
*/
std::auto_ptr<int> pdoseIn(new int); // A simple set case, but sill produces an error!?!
std::auto_ptr<DOSE_Calac> pdoseIn(new DOSE_Calac); // Original code, error found here at first.
};
#endif // MAINWINDOW_H
這是我的班,dose_calac.h。
#ifndef DOSE_CALAC_H
#define DOSE_CALAC_H
class DOSE_Calac
{
public:
// constructor
DOSE_Calac();
// set and get functions live here, removed for clarity/size.
// function for caulating DOSE indexpoints
int CalcDOSEPoints();
private:
unsigned int dyspnoeaScale;
unsigned int fev1;
bool smoker;
unsigned int anualExacerbations;
unsigned int doseIndexPoints;
};
#endif // DOSE_CALAC_H
任何幫助或建議感激地收到。
備註:'auto_ptr'在C++ 11中已棄用。 – iammilind 2012-04-03 05:07:16