Constructing non-const images from const images

From LRDE

Revision as of 15:04, 12 November 2014 by Bot (talk | contribs) (Don't include the menu if the page is used included in another page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)



Compiler error message (g++ 3.0.4):

undefined reference to `oln::image2d<oln::int_u<(unsigned)8>, type::bottom>
::image2d[in-charge](oln::image2d<oln::int_u<(unsigned)8>, type::bottom> const&)'

sample source 1:

1  const image2d<int_u8> test1(1,1);
2  image2d<int_u8> test2 = test1;

sample source 2:

1  struct foo
2  {
3	 foo(const image2d<int_u8> & img) : m_Img(img) {}
4	 image2d<int_u8> m_Img;
5  };
6  in main:
7  image2d<int_u8> test1(1,1);
8  foo bar(test1);

Explanation:
If you look into src/core/image{1,2,3}d.hh you will find:

1 image2d(const self& rhs); // w/o impl.

Why is there no definition for this contructor ?
Think about Olena image as a kind of "data pointer", when you copy an Olena image, the data are not copied, only the pointer is copied. Thus the data will be shared by both images. When you have a const image, it means you want the data to be const; constructing a non - const image from a const image will result in an image which can modify the data whereas we expected data as const. Hence this constructor was not defined to prevent from this.

Ok, but why having a declaration if there is no definition ?
See Const Images page for a detailed explanation.