c++11 - C++ std vector initalization in namespace -


this question has answer here:

im beginner in c++. created namespace , tried initialise std::vector of std::string objects, namespace variable

namespace  nshttpworker{      std::vector<string> nvmobileagents = {         "mozilla/5.0 (linux; u; android 4.0.3; ko-kr; lg-l160l build/iml74k) applewebkit/534.30 (khtml, gecko) version/4.0 mobile safari/534.30",         "mozilla/5.0 (linux; u; android 4.0.3; de-ch; htc sensation build/iml74k) applewebkit/534.30 (khtml, gecko) version/4.0 mobile safari/534.30",         "mozilla/5.0 (linux; u; android 2.3; en-us) applewebkit/999+ (khtml, gecko) safari/999.9",         "mozilla/5.0 (linux; u; android 2.3.5; zh-cn; htc_incredibles_s710e build/grj90) applewebkit/533.1 (khtml, gecko) version/4.0 mobile safari/533.1",         "mozilla/5.0 (linux; u; android 2.3.5; en-us; htc vision build/gri40) applewebkit/533.1 (khtml, gecko) version/4.0 mobile safari/533.1",         "mozilla/5.0 (linux; u; android 2.3.4; fr-fr; htc desire build/grj22) applewebkit/533.1 (khtml, gecko) version/4.0 mobile safari/533.1",         "mozilla/5.0 (linux; u; android 2.3.4; en-us; t-mobile mytouch 3g slide build/gri40) applewebkit/533.1 (khtml, gecko) version/4.0 mobile safari/533.1",         "mozilla/5.0 (iphone; u; cpu iphone os 5_1_1 mac os x; en) applewebkit/534.46.0 (khtml, gecko) crios/19.0.1084.60 mobile/9b206 safari/7534.48.3",         "mozilla/5.0 (iphone; u; cpu mac os x; en) applewebkit/420+ (khtml, gecko) version/3.0 mobile/1a543 safari/419.3",         "mozilla/5.0 (macintosh; intel mac os x 10_9_3) applewebkit/537.75.14 (khtml, gecko) version/7.0.3 safari/7046a194a",         "mozilla/5.0 (ipad; cpu os 6_0 mac os x) applewebkit/536.26 (khtml, gecko) version/6.0 mobile/10a5355d safari/8536.25",         "mozilla/5.0 (ipod touch; cpu iphone os 8_3 mac os x) applewebkit/600.1.4 (khtml, gecko) fxios/1.0 mobile/12f69 safari/600.1.4",         "mozilla/5.0 (iphone; cpu iphone os 8_3 mac os x) applewebkit/600.1.4 (khtml, gecko) fxios/1.0 mobile/12f69 safari/600.1.4",         "mozilla/5.0 (ipad; cpu iphone os 8_3 mac os x) applewebkit/600.1.4 (khtml, gecko) fxios/1.0 mobile/12f69 safari/600.1.4"     };  } 

this gave me error this:

worker.obj:-1: ошибка: lnk2005: "class std::vector<class std::basic_string<char, struct std::char_traits<char>,class std::allocator<char> >, class std::allocator<class std::basic_string<char, struct std::char_traits<char>,class std::allocator<char> > > > nsfacebookhttp::nvmobileagents"  (?nvmobileagents@nsfacebookhttp@@3v?$vector@v?$basic_string@du?  $char_traits@d@std@@v?$allocator@d@2@@std@@v?$allocator@v?$basic_string@du?  $char_traits@d@std@@v?$allocator@d@2@@std@@@2@@std@@a)  defined in mainwindow.obj 

so not possible make container initalisations in c++ namespace?

so not possible make container initalisations in c++ namespace?

of course it's possible. got linker error telling you, have multiple definitions of vector variable.

it looks have defined vector in translation unit, supposed have in header file included multiple times, write:

 namespace  nshttpworker{      extern std::vector<string> nvmobileagents;  } 

and move definition (initialization) separate .cpp file.


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -