Click to See Complete Forum and Search --> : Destructor Problem


lloydy
July 28th, 2004, 08:49 PM
I have a base class implemented in C#, and I am deriving a class from it in managed C++. The problem is when I try to include a destructor in the derived class I get the follwoing error

Protocol error LNK2001: unresolved external symbol "void __cdecl __CxxCallUnwindDtor(void (__thiscall*)(void *),void *)" (?__CxxCallUnwindDtor@@$$J0YAXP6EXPAX@Z0@Z)


The C# class inherits from IDisposable and has a Dispose and Desturctor method.

The reason I need to have a destructor is the program is currently holding resources without it (Comm Port)

Can anyone help?

The destructor code I am implementing is:

private:~SerialHandler(){ this->Close();} //Close is a function in the base class.

HELP :blush:

Thanks

DNA5122
August 3rd, 2004, 12:56 PM
Aren't Dispose and Finalize supposed to replace destructors? I could be very wrong about that, but it was my impression after reading about garbage collection.

lloydy
August 25th, 2004, 01:38 AM
Can anyone answer this?

manbaum
August 25th, 2004, 02:33 AM
lloydy, Can you post your code here? how you define your derived class?

I have my C# code as below:

using System;

namespace TestSharp
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class Class1
{
public Class1()
{
//
// TODO: Add constructor logic here
//
}

public void hello()
{
Console.WriteLine("Hello world from Class1.");
}
}
}


And C++ code as below:

// This is the main project file for VC++ application project
// generated using an Application Wizard.

#include "stdafx.h"

#using <mscorlib.dll>
#using <TestSharp.dll>
#include <tchar.h>

using namespace System;
using namespace TestSharp;

__gc class TestIt : public Class1
{
public:
TestIt(){};
private:
~TestIt() {};
};

// This is the entry point for this application
int _tmain(void)
{
// TODO: Please replace the sample code below with your own.
Console::WriteLine(S"Hello World");

TestIt * pclass1 = new TestIt();
pclass1->hello();

return 0;
}


It compiles and runs, everything is OK.