3

次のコードがあります。

//test.cpp
#include <Physical_file.h>
#include <boost\python.hpp>

using namespace boost::python;
using namespace FMS_Physical;

BOOST_PYTHON_MODULE(python_bridge)
{
    class_<Physical_file, boost::noncopyable>("pf")
        .def(init<const string&, optional<int, const string&>>())
    ;
}

//Physical_file.h
#include <fstream>
#include "tools.h"
using namespace std;

namespace FMS_Physical
{
    class Physical_file
    {
    public:
        fstream filefl;
        string workingDir;
        string fileName;
        int fileSize;
        block currBlock;
        block FHBuffer;
        bool opened;
        string openMode;

        /************
        functions
        ************/

        Physical_file(void);
        Physical_file(const string &FileName, int FileSize,const string &Dir = getCurrentPath());
        Physical_file(const string &FileName, const string &Type, const string &Dir = getCurrentPath());

        ~Physical_file(void);
    };
}

もう少しコードがありますが、質問とは無関係だと思います。

コードをコンパイルしようとすると、次のエラーが発生します。

Error   5   error C2664: 'FMS_Physical::Physical_file::Physical_file(const FMS_Physical::Physical_file &)' : cannot convert parameter 1 from 'const std::string' to 'const FMS_Physical::Physical_file &'   

(test.cpp 内の) コンストラクターの定義からを削除するとoptional、エラーは消えますが、オプションのパラメーターを取得できません。

VS2010、python27、および c++ ブースト ライブラリを使用してコンパイルしています。

このエラーが発生する理由と解決方法を説明できる人はいますか?

EDIT
次の行を使用して、代わりに3番目のコンストラクターを公開しようとしました:

.def(init<const string&, const string &, optional<const string &>>())

これによりエラーは発生しませんでした。

4

1 に答える 1

1

にデフォルトを与えるのを忘れましたFileSize。この宣言が機能するには、パラメーターinit<const string&, optional<int, const string&>> のみで呼び出すことができるコンストラクターが必要です。const string&現時点ではそのようなものはありません。これは、コンパイラの正確な苦情です。

于 2013-06-15T20:04:24.650 に答える