BaseArray<Vector> gives error c2248 ???



  • On 20/11/2016 at 22:03, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   17 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    So i have a custom class that needs an array of Vectors. As per standard Maxon guidelines, I'm using BaseArray.

    This is the declaration within the class:

    maxon::BaseArray<Vector> vecs;
    

    So here's the error:

    'maxon::BaseArray<Vector,0x010,BASEARRAYFLAGS_0,maxon::DefaultAllocator>::operator =' : cannot access private member declared in class 'maxon::BaseArray<Vector,0x010,BASEARRAYFLAGS_0,maxon::DefaultAllocator>' 
    

    Any idea why is this happening? and more importantly how to solve it?



  • On 21/11/2016 at 03:42, xxxxxxxx wrote:

    BaseArray does not provide a public copy constructor, thus the class you use it with can not have a 
    default copy constructor. Either implement your own copy constructor or do not use it/delete it.



  • On 21/11/2016 at 04:11, xxxxxxxx wrote:

    It seems to be the case. I expect to write my own constructors in my own classes. but I can't really do that with Vector, which is a native C4D class... That's why i'm surprised. I would have expected Vector to work natively with BaseArray



  • On 21/11/2016 at 04:42, xxxxxxxx wrote:

    It's got nothing to do with the Vector type, the BaseArray does not support a copy assignment or
    copy constructor. This is a "security" feature to prevent you from accidentally writing code that could
    have immense performance impacts. If you want to copy a BaseArray, do it explicitly with its CopyFrom()
    method. Of course, you can implement your own copy constructor/assignment operator that uses  the
    CopyFrom() method.

    Best,
    -Niklas



  • On 21/11/2016 at 05:11, xxxxxxxx wrote:

    I'm not trying to copy a basearray. I'm trying to create a new one....



  • On 21/11/2016 at 09:43, xxxxxxxx wrote:

    Well show your code then. How am I supposed to know if you're only telling me that now. 😪



  • On 22/11/2016 at 00:59, xxxxxxxx wrote:

    Hi Niklas, i showed my code at the beginning. it always errors on the declaration

    I even setup a dummy which inherits Vector as specified in this portion of the SDK 
    https://developers.maxon.net/docs/Cinema4DCPPSDK/html/movecopy.html

    class Example2 : public Vector
    {
    	MAXON_DISALLOW_COPY_AND_ASSIGN(Example2);
    public:
    	Example2() {}
    	Example2(Example2&& src) : Vector(std::move(src)), _val2(std::move(src._val2))
    	{
    		src._val2 = 0;
    	}
    	MAXON_OPERATOR_MOVE_ASSIGNMENT(Example2);
    private:
    	Int _val2 = 1;
    };
      
    class Dummy{
      
    public:
    	//base components
    	maxon::BaseArray<Example2> vecs;
    };
    

    still, i get error C2248

    'maxon::BaseArray<Example2,0x010,BASEARRAYFLAGS_0,maxon::DefaultAllocator>::operator =' : cannot access private member declared in class 'maxon::BaseArray<Example2,0x010,BASEARRAYFLAGS_0,maxon::DefaultAllocator>' 
    

    and this is how i gave up on maxon::BaseArray and started using std::vector 😂
    so far, no problems :D



  • On 22/11/2016 at 08:30, xxxxxxxx wrote:

    Hi !

    You need to disable copy constructor and copy assignment operator or implement them for Dummy and not for Example.

    Also I think that inherit Vector is a bad idea.

      
    class Dummy {  
      MAXON_DISALLOW_COPY_AND_ASSIGN(Dummy);  
    public:
    	//base components
    	maxon::BaseArray<Example2> vecs;
    };
    

    > and this is how i gave up on maxon::BaseArray and started using std::vector
    Because std::vector allows possible costly implicit copy of it self.



  • On 22/11/2016 at 09:09, xxxxxxxx wrote:

    Just to clarify, the problem is not the Vector  class, which is in fact copy constructible/assignable, but the
    BaseArray  class, which is neither copy constructible nor copy assignable. The fact that you have a member
    of type BaseArray in your Dummy  class causes this issue: When the compiler automatically generates the
    copy constructor and assignment operator for the Dummy  class, it finds that the BaseArray member can
    not be copy constructed/assigned, thus the automatic generation of the constructor/assignment operator fails.

    Best,
    -Niklas



  • On 22/11/2016 at 12:55, xxxxxxxx wrote:

    Thank you Remotion, Niklas. I have to admit that it never crossed my mind that the main class (dummy) would be tho one to apply the maxon trickery. I read the following in the sdk:

    In the API there are strict requirements as to how classes need to be implemented, so that they can function e.g. with sort and array templates.

    To me it meant that whatever custom classes i wanted in insert INTO maxon arrays had to implement the techniques outlined in the sdk for the copy/move/assignment, not custom classes that have maxon arrays as members.

    In any case, for now the std::vector class works well - at least for the prototyping stage. Remotion, i am not copying the vectors anywhere, but i am using std::move() in parts, which doesn't affect performance all that much.

    I am thinking that before release i could convert all my std::vector's to maxon::BaseArray's, if they don't cause any headaches.

    here's a generalization of what i'm doing:

    class Container{
    public:
    	std::vector<A> as;
    	std::vector<B> bs;
      
    	//data, constructors, functions
    	//
    	//etc.
    };
      
    class A{
    public:
    	Container * container;
    	std::vector<B*> b_ptrs;
      
    	//data, constructors, functions
    	//
    	//etc.
    };
      
    class B{
    public:
    	Container * container;
    	std::vector<A*> a_ptrs;
      
    	//data, constructors, functions
    	//
    	//etc.
    };
    

    so i have a container that holds arrays of custom objects. each object has a pointer to a container, and is an array of pointers to other objects in the container. It's a special case of linked lists.

    As i said, it works well with std::vector's. Would I be able to do this with maxon::BaseArray's?


Log in to reply