I'm trying to pass a reference to a vector of vecs to my mesh constructor. I get the following:

error c2582 operator function is unavailable in...

I do not want a copy of these vecs, and have tried passing by both const& and pointer with no success. The vecs std::vector does not contain this field, nor does is have a similar constructor. I'm using Visual Studio 2013. Any assistance is appreciated.

//////Main

myVecs = ptData.getVecs();//this function returns pts from: std::vector<Vec3*>& pts;
dMesh mesh = dMesh(myVecs);

//////Derived Mesh Class Header/////

#include <isostream>
#include <vector>
#include "BaseMesh.h"

class dMesh : public BaseMesh {
private: 
    void init();
    std::vector <Vec3*>& vecs;

public:
    dMesh();
    dMesh(std::vector<Vec3*>& vecs);
};

////.cpp

dMesh::dMesh(std::vector<Vec3*>& vecs):
vecs(vecs){

   init();
}

void dMesh::init();///"use data from vector"
有帮助吗?

解决方案

Since I was unable to find a direct example of this anywhere else, I've decided to post the working implementation for reference. I wouldn't make any claims that this is ideal, but at the moment, this is providing the functionality I expect. Feel free to comment if there are suggested improvements:

//Base Class Header:

`
#include <vector>

class BaseMesh{
pulbic:
    std::vector<Vec3*>* vecs;
    BaseMesh();
    BaseMesh(std::vector<Vec3*>* vecs);
};`

//Base Class Constructor:

`
BaseShape::BaseShape();
BaseShape::BaseShape(std::vector<ntVec3*>* vecs = nullptr):
vecs(vecs){
}`

//Derived Class Header:

`
#include <vector>
#include "BaseMesh.h"

class dMesh : public BaseMesh {
private: 
    void init();
public:
    dMesh();
    dMesh(std::vector<Vec3*>* vecs);
};`

//Derived Mesh Constructor:

`
dMesh::dMesh(){}

dMesh::dMesh(std::vector<Vec3*>* vecs):
BaseShape(vecs){
    init();
}`
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top