0

I have a two dimensional vector

std::vector< std::vector<unsigned long int> > reference_index_vector(2, std::vector<unsigned long int> ());

and I have other two dimensional vector

std::vector< std::vector<unsigned long int> > read_index_vector(2, std::vector<unsigned long int> ());

I need both the vector in other files so I defined them as extern in .h file, however on compilation I get errors

../read_index.cpp:22:65: error: redefinition of ‘std::vector > read_index_vector’ std::vector< std::vector< long unsigned int> > read_index_vector(2, std::vector< long unsigned int> ());^ In file included from ../read_index.cpp:17:0: ../read_index.h:16:54: note: ‘std::vector > read_index_vector’ previously declared here extern std::vector< std::vector > read_index_vector(2, std::vector ());

Hashim
  • 307
  • 1
  • 5
  • 16
  • We might need to see a bit more code then this... such as where are you defining it and how are you using it? also are you declaring this inside of a class? – AresCaelum Jan 20 '17 at 11:25
  • 1
    Open your C++ book to the chapter that describes the `extern` keyword, what it means, and how to do what you want to do. – Sam Varshavchik Jan 20 '17 at 11:26
  • 1
    in the `extern` declaration, do not include the initializers – M.M Jan 20 '17 at 11:29
  • 1
    @M.M Thanks a lot – Hashim Jan 20 '17 at 11:33
  • @SamVarshavchik It's not a duplicate of provided link. Comment by `M.M` was helpful – Hashim Jan 20 '17 at 11:37
  • @Hashim if that was the issue you probably should have included the extern in your sample code. From what you provided it looked like that was how you were defining it not declaring it. – AresCaelum Jan 20 '17 at 14:17

0 Answers0