2015-05-20 96 views
-5

我想創建一個結構在C++中的列表,但出現錯誤的列表:創建C++中的結構

在聲明無效型前»;«令牌

小例子:

#include <list> 
#include <string> 
#include <iostream> 

using namespace std; 

int main(int argc, char** argv) 
{ 
    struct test { 
     string a1; 
     string a2; 
     int b1; 
     int b2; 
    }; 
    list<TBildpaar> Files; 
} 
+10

什麼是'TBildpaar'?你的意思是'list '? – 0x499602D2

+0

所以你不小心把't''標識符完成了'TBildpaar'。你看到錯誤,按Ctrl + A和Ctrl + C不看代碼並在這裏發佈... – LogicStuff

回答

1
#include <list> 
#include <string> 
#include <iostream> 

using namespace std; 

typedef struct { 
    string a1; 
    string a2; 
    int b1; 
    int b2; 
}test; 

int main(int argc, char** argv) 
{ 

    list<test> Files; 
} 

你去那裏。

+3

因爲這是C++,所以你不必做'typedef struct {} foo;'。 'struct foo {};''是C++的方法,因爲C++在每次使用結構體名 – NathanOliver

+0

時都不必使用'struct',所以你肯定是對的,我只是喜歡這樣做。 – Abel

+1

那麼這些變化中的哪一個實際上回答了這個問題?是否真的有必要添加一個奇怪的'typedef'並將'test'移動到更廣的範圍?或者你只需​​要用'test'替換'TBildpaar'?無論你喜歡什麼, –