2016-12-22 14 views
0

struct内のベクトルへのポインタの値にはどうすればアクセスできますか? [1]構造体内のベクトルへのポインタへのアクセス

Error C2678 binary '==': no operator found which takes a left-hand operand of type 'std::vector<bool,std::allocator<_Ty>>' (or there is no acceptable conversion) 

にはどうすればDPに格納された値にアクセスすることができます.path [2]:

次のコンパイルエラーが発生し
#include <iostream> 
#include <vector> 

using namespace std; 

struct item { 
    int value; 
    vector<bool> pb; 
    vector<bool> *path = &pb; 
}; 

int main(int argc, char* argv[]) { 
    vector<item> dp(10); 
    for (int n = 0; n < 10; n++) 
     dp[n].pb = vector<bool>(10); 

    if (dp[1].path[2] == true) 
     cout << "true"; 
    else cout << "false"; 
} 

:私は、次のコードを持っていますか?

+2

構造体にないベクトルへのポインタからの値と同じ方法でアクセスします。 – juanchopanza

答えて

2

パスはベクトルへのポインタです。あなたはそれがまた

if ((*(dp[1].path))[2] == true) 

または

if (dp[1].path->operator[](2) == true) 
+0

ありがとう@WhozCraigそれを指摘する – user3286661

1

を指すベクトルの値にアクセスするには、以下を行う必要があり、あなたも

checks whether n is within the bounds of valid elements in the vector

あるatfunctionを使用することができますコード例

if (dp[1].path->at(2) == true) 
関連する問題