0

作成されたedge_arrayがボタンクリックハンドラーで使用されたときに未定義の識別子として表示される理由がよくわかりません。cli/c++に慣れていないので、VS2010を使用していることに注意してください。また、CLIマネージドのものを組み合わせてブーストアンマネージドコードを使用すると、どんな助けでも大歓迎です

namespace Prototype {
    //using namespace boost;
    using namespace boost::graph;
    using namespace boost::numeric::ublas;
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    using namespace System::Runtime::InteropServices;
    using namespace msclr::interop;

    /// <summary>
    /// Summary for Form1
    /// </summary>
    //graph properties types
    typedef boost::property<boost::edge_weight_t, double> EdgeWeightProperty;
    typedef boost::property<boost::vertex_name_t, std::string, boost::property<boost::vertex_potential_t, int, boost::property<boost::vertex_update_t, double> > > StationProperties;

    //graph type
    typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, StationProperties, EdgeWeightProperty> Graph;

    //instantiation
    Graph g;

    // Property accessors
    boost::property_map<Graph, boost::vertex_name_t>::type station_name = get(boost::vertex_name, g);
    boost::property_map<Graph, boost::vertex_potential_t>::type station_capacity = get(boost::vertex_potential, g);
    boost::property_map<Graph, boost::vertex_update_t>::type station_update = get(boost::vertex_update, g);
    boost::property_map<Graph, boost::edge_weight_t>::type edge_distance = get(boost::edge_weight, g);

    //vertex descriptor
    typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;

    //transition matrix definition and station vector definition
    matrix<double> trans(6,6);
    vector<double> stat(6);

    bool inserted;
    int counter = 0;

    typedef boost::graph_traits<Graph>::edge_descriptor edge_descriptor;

    edge_descriptor e;

    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();

            //station vector definition
            stat(0) = 1000;
            stat(1) = 1000;
            stat(2) = 1000;
            stat(3) = 1000;
            stat(4) = 1000;
            stat(5) = 1000;

            //transition matrix
            trans(0,0) = 0; trans(0,1) = 1; trans(0,2) = 0; trans(0,3) = 0; trans(0,4) = 0; trans(0,5) = 0;
            trans(1,0) = 0.25; trans(1,1) = 0; trans(1,2) = 0.75; trans(1,3) = 0; trans(1,4) = 0; trans(1,5) = 0;
            trans(2,0) = 0; trans(2,1) = 0.33; trans(2,2) = 0; trans(2,3) = 0.33; trans(2,4) = 0.33; trans(2,5) = 0;
            trans(3,0) = 0; trans(3,1) = 0; trans(3,2) = 0.75; trans(3,3) = 0; trans(3,4) = 0; trans(3,5) = 0.25;
            trans(4,0) = 0; trans(4,1) = 0; trans(4,2) = 0.75; trans(4,3) = 0; trans(4,4) = 0; trans(4,5) = 0.25;
            trans(5,0) = 0; trans(5,1) = 0; trans(5,2) = 0; trans(5,3) = 0.5; trans(5,4) = 0.5; trans(5,5) = 0;

            //station graph declerations

            Vertex u0;
            u0 = add_vertex(g);
            station_name[u0] = "Kennington";
            station_capacity[u0] = 2000;
            station_update[u0] = stat(0);

            Vertex u1;
            u1 = add_vertex(g);
            station_name[u1] = "Elephant & Castle";
            station_capacity[u1] = 2000;
            station_update[u1] = stat(1);

            Vertex u2;
            u2 = add_vertex(g);
            station_name[u2] = "London Bridge";
            station_capacity[u2] = 3000;
            station_update[u2] = stat(2);

            Vertex u3;
            u3 = add_vertex(g);
            station_name[u3] = "Bank";
            station_capacity[u3] = 3000;
            station_update[u3] = stat(3);

            Vertex u4;
            u4 = add_vertex(g);
            station_name[u4] = "Borough";
            station_capacity[u4] = 2000;
            station_update[u4] = stat(4);

            Vertex u5;
            u5 = add_vertex(g);
            station_name[u5] = "Oval";
            station_capacity[u5] = 3000;
            station_update[u5] = stat(5);

            typedef std::pair<int,int> Edge;
            Edge edge_array[] = {
                Edge(u0, u0), Edge(u0, u1),Edge(u0, u2),Edge(u0, u3),Edge(u0, u4),Edge(u0, u5),
                Edge(u1, u0), Edge(u1, u1),Edge(u1, u2),Edge(u1, u3),Edge(u1, u4),Edge(u1, u5),
                Edge(u2, u0), Edge(u2, u1),Edge(u2, u2),Edge(u2, u3),Edge(u2, u4),Edge(u2, u5),
                Edge(u3, u0), Edge(u3, u1),Edge(u3, u2),Edge(u3, u3),Edge(u3, u4),Edge(u3, u5),
                Edge(u4, u0), Edge(u4, u1),Edge(u4, u2),Edge(u4, u3),Edge(u4, u4),Edge(u4, u5),
                Edge(u5, u0), Edge(u5, u1),Edge(u5, u2),Edge(u5, u3),Edge(u5, u4),Edge(u5, u5)
            };
        //all other declerations

    private:
        void Build_Click(System::Object^  sender, System::EventArgs^  e) {
            //station_name[u0] = marshal_as<std::string> (this->NameBox0->Text);
            station_name[0] = marshal_as<std::string> (this->NameBox0->Text);
            station_name[1] = marshal_as<std::string> (this->NameBox1->Text);
            station_name[2] = marshal_as<std::string> (this->NameBox2->Text);
            station_name[3] = marshal_as<std::string> (this->NameBox3->Text);
            station_name[4] = marshal_as<std::string> (this->NameBox4->Text);
            station_name[5] = marshal_as<std::string> (this->NameBox5->Text);

            station_capacity[0] = System::Convert::ToInt32(this->Capbox0->Text);
            station_capacity[1] = System::Convert::ToInt32(this->Capbox1->Text);
            station_capacity[2] = System::Convert::ToInt32(this->Capbox1->Text);
            station_capacity[3] = System::Convert::ToInt32(this->Capbox1->Text);
            station_capacity[4] = System::Convert::ToInt32(this->Capbox1->Text);
            station_capacity[5] = System::Convert::ToInt32(this->Capbox5->Text);

            for (unsigned i = 0; i < trans.size1 (); ++ i){
                for (unsigned j = 0; j < trans.size2 (); ++ j){
                    if (trans(i,j) > 0.1)
                    {
                        boost::tie(e, inserted) = boost::add_edge(edge_array[counter].first,edge_array[counter].second,g);
                        edge_distance[e] = trans(i,j);
                    }
                    ++counter;
                }
            }
        }
    };
4

1 に答える 1

1

Form1コンストラクター内でedge_arrayを宣言および初期化しています。Form1()のスコープ内で変数を宣言するため、Form1()のスコープ内にのみ存在します。

Form1()の外部では、edge_arrayは未定義です。

edge_arrayをButton_Clickに表示するには、宣言されているようにクラスの外でvector<double> stat宣言するか、他のクラスメンバー変数のようにクラス内で宣言する必要があり//all other declerationsます。

コンストラクター内で配列を初期化することはできます。

于 2011-08-03T20:48:29.200 に答える