I have a short question the class methods. I have written a class (a home-brew mathematical function) which has 4 private members and two public ones the two public ones are std::vector<double> type. The main method returns a std::vector<double> by filling up one of the public member vectors with data. the question is whether I have to overload the operator [] in order to retrieve the elements of this vector. So far I got this error message:
no match for ‘operator[]’ in ‘data[i]’
If I have to do that then how do you overload the [] operator to retrieve elements of the result of member method.
thanks for the answer. Are you using c++11 option when you compiled this code? I only have the -std=c++0x option. I get an error message when I compile this.
/tmp/cc3LZeAf.o: In function `main':
class_vector.cpp:(.text+0x41): undefined reference to `std::cout'
class_vector.cpp:(.text+0x46): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(double)'
class_vector.cpp:(.text+0x56): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/cc3LZeAf.o: In function `__static_initialization_and_destruction_0(int, int)':
class_vector.cpp:(.text+0xa5): undefined reference to `std::ios_base::Init::Init()'
class_vector.cpp:(.text+0xaa): undefined reference to `std::ios_base::Init::~Init()'
/tmp/cc3LZeAf.o: In function `__gnu_cxx::new_allocator<int>::deallocate(int*, unsigned int)':
class_vector.cpp:(.text._ZN9__gnu_cxx13new_allocatorIiE10deallocateEPij[__gnu_cxx::new_allocator<int>::deallocate(int*, unsigned int)]+0xd): undefined reference to `operator delete(void*)'
/tmp/cc3LZeAf.o:(.eh_frame+0x8b): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status