Reputation: 2027
My snippet of code:
void
RMWavefrontFileImporter::loadVertexIntoVector(
const std::vector<std:string> lineElements,
std::vector<const RM3DVertex>* vertices)
{
assert(vertices);
std::unique_ptr<const RM3DVertex> verticeRef = verticeWithElements(lineElements);
const RM3DVertex* vertex = vertexRef.get();
assert(vertex);
vertices->push_back(*vertex);
}
The error message I'm getting:
Cannot initialize a parameter of type 'void *' with an lvalue of type 'const RM3DVertice *'
I'm failing to see the problem. Is there anything obvious I'm missing?
Upvotes: 2
Views: 493
Reputation: 153800
The value type T
of a std::vector<T>
needs to be CopyInsertible or MoveInsertible. To be either, it is necessary to call the moral equivalent of
T* tptr = <allocate-memory-over-here-and-make-it-look-like-a-T*>
new(tptr) T(std::forward<Args>(args);
With T
being a const
type this doesn't work, e.g., because there is no conversion from T*
to void*
if T
is of the form X const
. You want to remove the const
from std::vector<const RM3DVertice>
.
Upvotes: 6