2

the full message is:

error LNK2019 : unresolved external symbol "__declspec(dllimport) public: virtual __cdecl FRenderResource::~FRenderResource(void)" (__imp_ ? ? 1FRenderResource@@UEAA@XZ) referenced in function "int public: __cdecl FIndexBuffer::FIndexBuffer(class dtor$0 const &)'::1'::dtor$0" (? dtor$0@ ? 0 ? ? ? 0FIndexBuffer@@QEAA@AEBV0@@Z@4HA)

It appears when I write like this:

FRawStaticIndexBuffer indBuffer = obj->StaticMesh->RenderData->LODResources[0].IndexBuffer;

But if I change it to this:

FRawStaticIndexBuffer* indBuffer = &obj->StaticMesh->RenderData->LODResources[0].IndexBuffer;

everything fine. But what's the difference? Why pointer is safe and copy not?

nikitablack
  • 4,359
  • 2
  • 35
  • 68

2 Answers2

3

"Why pointer is safe and copy not?"

Neither is safe.

With the copy, you have the error that a destructor has not been defined. (Missing symbol)

With the pointer, even though your program currently runs without a noticeable problem, you have the error that a destructor has not been called. (Memory/resource leak)

You need to find out why your linker isn't finding the definition to FRenderResource::~FRenderResource() anywhere, even though you declared it.

Drew Dormann
  • 59,987
  • 13
  • 123
  • 180
  • Thank you. But I wrote that with pointer everything is fine. Program compiles and run. I'm total newby to C++, but as far as I know destructors are optional, I don't need to declare them if I doan't want. And in my example there's destructor implementation. – nikitablack Jun 17 '14 at 14:24
1

It's because a pointer is a memory address so if you take a memory address of some object (the part to the right of the equal sign) and store it in a pointer (which is a memory address object) then you're just saving a memory address to a memory address object so it'll always work.

It's like this: Bob lives at 123 Fake Street. 123 Fake Street is a pointer to Bob. Bob may or may not be home, but his house is always there. If Bob isn't home and you try to get Bob by going into his home then his security alarm will go off.

I agree that none of this is safe, but this explains what is happening.

Alex
  • 1,082
  • 17
  • 27