2011-02-18 7 views
-1

bee.cpp什麼錯我的C++名單<string>

  list<string> urls; 

       urls.push_back ("one"); 
       urls.push_back ("two"); 
       urls.push_back ("Three"); 
       urls.sort(); 

        TP(urls); 

TP.h

namespace std { 

     class TP { 
     public: 
      TP(list<string> u); 
      virtual ~ThreadPool(); 
     }; 

    } 

TP.C++

TP::TP(list<string> u) { 
     list<string>::iterator it; 
     for (it=mylist.begin(); it!=mylist.end(); ++it) 
      cout << " " << *it; 
    } 

    TP::~TP() { 
     // TODO Auto-generated destructor stub 
    } 

它工作在同樣的功能下一個文件,如果我使用類它顯示我錯誤

../src/Bee.cpp: In function ‘int main()’: 
../src/Bee.cpp:31: error: conflicting declaration ‘std::TP u’ 
../src/Bee.cpp:24: error: ‘u’ has a previous declaration as ‘std::list<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > u’ 
} 
#endif /* TP_H_ */ 

TP.h 
+4

你不允許的東西添加到`std`命名空間。我不知道這與你的問題有什麼關係(因爲我看不懂你的代碼),但你不應該這樣做。 – 2011-02-18 07:05:09

回答

2

弗雷德拉森已經推測你的代碼是錯誤的,因爲你已經非法添加東西到std::命名空間。確實如此。然而,看着'std :: TP u'的錯誤,顯然你沒有顯示相關的代碼。您在bee.cpp中有兩個聲明u,並且您的代碼摘錄都不顯示。

0
mylist.begin(); it!=mylist.end(); 

應該

u.begin(); it!=u.end();