Having this issue with C++/CLI that's troubling me for a real long time and almost everything I've tried has failed. The problem is when I'm trying to create an instance of the GenDen reference managed type. I keep encountering error C2512: 'Instruction::GenDen' : no appropriate default constructor available. I'm posting the pieces of code here:
Code:
Code:
// GenDen.h
#pragma once
#include "prm.h"
namespace Triad{
public ref class GenDen : public Prm
{
public:
GenDen();
GenDen(Slots slot);
};
}
Code:
// GenDen.cpp
#include "stdafx.h"
#include " GenDen.h"
using namespace Triad;
GenDen::GenDen (): Prm(){} //default constructor
GenDen::GenDen(Slots slot) : Prm()
{
try{
Initialize(slot);
}
catch(DenException^ e){
throw e;
}
}
void GenDen::Initialize(Slots slot){
//Whole bunch of Code related to this Initialize function
}
Main Project File:
Code:
// Instruction.cpp
#include "stdafx.h"
#include "Form1.h"
#include "GenDen.h"
#include "prm.h"
using namespace Instruction;
void Form1::OpenInstruction(void)
{
try {
Den = gcnew GenDen (Triad::Slots::Slot8); //results in error C2512: 'Instruction::GenDen' : no appropriate default constructor available
// Den = gcnew GenDen (); //declaring it like this also results in the same error C2512
}
catch (Pier::PierException^ ge) {
throw ge;
}
}
Code:
//Form1.h
#pragma once
#include "prm.h"
namespace Instruction {
ref class GenDen;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private:
void Open Instruction ();
private:
GenDen^ Den; //declaring a handle of GenDen managed type
};
}
Code:
//Prm.h
#pragma once
namespace Triad
{
using namespace System;
using namespace System::Windows::Forms;
public enum class Slots{
Slot1,
Slot2,
Slot3,
Slot4,
Slot5,
Slot6,
Slot7,
Slot8,
Slot9,
Slot10,
Slot11,
Slot12,
Slot13,
Slot14,
Slot15,
Slot16,
Slot17,
Slot18,
Slot19,
Slot20
};
public ref class Prm{
public:
Prm(){ errorCode = 0; handle = 0; }
virtual void Initialize(Slots slot){}
virtual void Reset(){}
};
}
Can anyone help me on where I'm going wrong? All this is being done in VS 2010 C++ .NET 4.0. I'm new to C++/CLI, and figuring out all the intricacies has been interesting (even though they took a while). But this particular issue is proving beyond me.
Thanks