c++ - Cannot construct object -


i spend last 2 hours trying figure out why following code won't compile , got nothing. relevant parts of code follows (full code here http://pastebin.com/z78iy3aa (hpp) , http://pastebin.com/5mc6twet (cpp) here if needed):

/* file: du1simd.hpp */  #include <iterator> #include <cstdint> #include <new>  template< typename t, typename s> class simd_vector;  template<typename t, typename s> class simd_vector_iterator     : public std::iterator<std::random_access_iterator_tag, t> {     typedef         typename simd_vector<t, s>::iterator         self_type;     typedef         typename std::iterator<std::random_access_iterator_tag, t>::pointer         pointer;     typedef         typename std::iterator<std::random_access_iterator_tag, t>::reference         reference;     typedef         typename std::iterator<std::random_access_iterator_tag, t>::value_type         value_type;     typedef         typename             std::iterator<std::random_access_iterator_tag, t>::difference_type         difference_type;  public:     simd_vector_iterator()         : ptr_(nullptr) {}     explicit simd_vector_iterator(pointer ptr)         : ptr_(ptr) {}     explicit simd_vector_iterator(const self_type & other)         : ptr_(other.ptr_) {}     explicit simd_vector_iterator(self_type && other)         : ptr_(other.ptr_) {         other.ptr_ = nullptr;     }      /*     operators random access iterator here     */   private:     pointer ptr_; };  template< typename t, typename s> simd_vector_iterator< t, s> operator+(std::ptrdiff_t n, simd_vector_iterator< t, s> a) {     return += n; }  template< typename t, typename s> simd_vector_iterator< t, s> operator-(std::ptrdiff_t n, simd_vector_iterator< t, s> a) {     return -= n; }  template<typename t, typename s> class simd_vector {  public:     typedef simd_vector_iterator<t, s> iterator;      explicit simd_vector(std::size_t s) throw(std::bad_alloc) {         pointer_to_allocated_memory_ =             ::operator new(sizeof(t) * s + sizeof(s));          uintptr_t pointer_to_allocated_memory =             (uintptr_t) pointer_to_allocated_memory_;         uintptr_t pointer_to_alligned_memory =             pointer_to_allocated_memory + sizeof(s)             - pointer_to_allocated_memory % sizeof(s);         data_s_ = reinterpret_cast<s*>(pointer_to_alligned_memory);         data_t_ = reinterpret_cast<t*>(pointer_to_alligned_memory);     }      ~simd_vector() {         ::operator delete(pointer_to_allocated_memory_);     }      iterator begin() {         iterator i(data_t_);         return i;     }      iterator end() {         /*...*/     }      std::size_t size() {         return count_;     }      /*...*/   private:     void * pointer_to_allocated_memory_;     std::size_t count_;     s * data_s_;     t * data_t_; }; 

and test code:

/* file: du1simd.cpp */  #include "du1simd.hpp"  typedef int t; struct s {     t a, b, c; };  int main(int argc, char ** argv) {     simd_vector<t, s> sv(5);     *(sv.begin()) = 1;     return 0; } 

when try compile this, see following error:

in file included du1simd.cpp:8:0: du1simd.hpp: in instantiation of ‘simd_vector<t, s>::iterator simd_vector<t, s>::begin() [with t = int; s = s; simd_vector<t, s>::iterator = simd_vector_iterator<int, s>]’: du1simd.cpp:17:16:   required here du1simd.hpp:192:16: error: no matching function call ‘simd_vector_iterator<int, s>::simd_vector_iterator(simd_vector<int, s>::iterator&)’          return i;                 ^ du1simd.hpp:192:16: note: candidate is: du1simd.hpp:59:5: note: simd_vector_iterator<t, s>::simd_vector_iterator() [with t = int; s = s]      simd_vector_iterator()      ^ du1simd.hpp:59:5: note:   candidate expects 0 arguments, 1 provided 

which think tells me don't have appropriate constructor, when @ code of simd_vector_iterator see constructor (imho) matches signature :/

would kind me this?

disclosure: yes, homework assigment. no, don't want finish me. need "won't compile" situation.

vs2013 throws following error, has better message:

error c2558: class 'simd_vector_iterator' : no copy constructor available or copy constructor declared 'explicit'

removing explicit keyword on copy constructor should enough:

simd_vector_iterator(const self_type & other) : ptr_(other.ptr_) {} 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -