fork download
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. class data {
  5. private:
  6. std::vector<char> cdata; //
  7. std::vector<double> ddata; // container for 64-bit floating point
  8. char dtype;
  9. public:
  10. data(char type) : cdata(10, 'c'),
  11. ddata(10, 3.00),
  12. dtype(type){}
  13.  
  14. template <typename T>
  15. void get_data(std::vector<T>& outdata) const {
  16. switch (dtype) {
  17. case 'c':
  18. outdata = cdata;
  19. break;
  20. case 'd':
  21. outdata = ddata;
  22. break;
  23. default:
  24. std::cerr << "Unknown data format" << std::endl;
  25. break;
  26. }
  27. }
  28.  
  29. };
  30.  
  31. int main ()
  32. {
  33. data mydata('c');
  34. std::vector<double> v;
  35. mydata.get_data(v);
  36. }
  37.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'void data::get_data(std::vector<T>&) const [with T = double]':
prog.cpp:35:22:   required from here
prog.cpp:18:21: error: no match for 'operator=' (operand types are 'std::vector<double>' and 'const std::vector<char>')
             outdata = cdata;
                     ^
In file included from /usr/include/c++/5/vector:69:0,
                 from prog.cpp:1:
/usr/include/c++/5/bits/vector.tcc:167:5: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = double; _Alloc = std::allocator<double>]
     vector<_Tp, _Alloc>::
     ^
/usr/include/c++/5/bits/vector.tcc:167:5: note:   no known conversion for argument 1 from 'const std::vector<char>' to 'const std::vector<double>&'
In file included from /usr/include/c++/5/vector:64:0,
                 from prog.cpp:1:
/usr/include/c++/5/bits/stl_vector.h:448:7: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = double; _Alloc = std::allocator<double>]
       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
       ^
/usr/include/c++/5/bits/stl_vector.h:448:7: note:   no known conversion for argument 1 from 'const std::vector<char>' to 'std::vector<double>&&'
/usr/include/c++/5/bits/stl_vector.h:470:7: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = double; _Alloc = std::allocator<double>]
       operator=(initializer_list<value_type> __l)
       ^
/usr/include/c++/5/bits/stl_vector.h:470:7: note:   no known conversion for argument 1 from 'const std::vector<char>' to 'std::initializer_list<double>'
stdout
Standard output is empty