SO i have a function that returns a call to another function which returns a class, and I am getting a compiler error...

AoE2Wide.cpp(179): error C3073: 'AoE2Wide::Patch' : ref class does not have a user-defined copy constructor

return FindPatchForExe(fileSize, exeMd5, exeFilename);

Here is the definition i made for the class up above...

Any ideas?

namespace AoE2Wide
{
	Patch::Patch(const Patch^ p)
	{
		PatchFilepath = p->PatchFilepath;
		FileSize = p->FileSize;
		Md5 = p->Md5;
		Version = p->Version;
		InterfaceDrsPosition = p->InterfaceDrsPosition;
		InterfaceX1DrsPosition = p->InterfaceX1DrsPosition;
		Items = p->Items;
	}
};

Recommended Answers

All 5 Replies

complete code would be usefull. I guess you miss typed there and its:

Patch::Patch(const Patch& p)
not
Patch::Patch(const Patch^ p)

When I did the & it wouldn't work. The problem is I am using a private ref class, not a standard class, which I read is different...

When I did the & it wouldn't work. The problem is I am using a private ref class, not a standard class, which I read is different...

Could you post the class declaration?

I think the biggest issue you're having is your constructor doesn't match the declaration, though I really can't tell without more information.

Is FindPatchForExe a new patch object or is it a function? If it's an object, it can't initialize from the constructor you posted.

ref class does not have a user-defined copy constructor

I bet you're using stack semantics with a copy constructor expecting managed references:

using namespace System;

ref class example {
public:
    example()
    {
        Console::WriteLine("Default constructor");
    }

    example(const example^ ref)
    {
        Console::WriteLine("Reference copy contructor");
    }
};

int main(array<String ^> ^args)
{
    example a;
    example b = a; // Uh-oh, no copy constructor for stack semantics
}

This can be fixed by converting the object to a reference handle, which will call the correct copy constructor:

example b = %a;

Or you can support both managed references and stack semantics in the copy constructor:

using namespace System;

ref class example {
public:
    example()
    {
        Console::WriteLine("Default constructor");
    }

    example(const example% obj)
    {
        Console::WriteLine("Stack copy constructor");
    }

    example(const example^ ref)
    {
        Console::WriteLine("Reference copy contructor");
    }
};

int main(array<String ^> ^args)
{
    example a;
    example b = a; // Now it works
    example d = gcnew example(); // This works too
}
commented: Perfect +0

Yup, that fixed it. Ty :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.