I have this error : "no appropriate default constructor available " in Form1.h.

Form1.h

#pragma once
#include <time.h>
#include <windows.h>
ref class CCenter;

namespace RCK {

        using namespace System;
        using namespace System::ComponentModel;
        using namespace System::Collections;
        using namespace System::Windows::Forms;
        using namespace System::Data;
        using namespace System::Drawing;

        /// <summary>
        /// Summary for Form1
        ///
        /// WARNING: If you change the name of this class, you will need to change the
        ///          'Resource File Name' property for the managed resource compiler tool
        ///          associated with all .resx files this class depends on.  Otherwise,
        ///          the designers will not be able to interact properly with localized
        ///          resources associated with this form.
        /// </summary>
        public ref class Form1 : public System::Windows::Forms::Form
        {
        public:
                Form1(void)
                {
                        InitializeComponent();
                        CCenter^ Engine = gcnew CCenter(0);
                        //
                        //TODO: Add the constructor code here
                        //
                }
...

Center.h

#pragma once
#include "StandsQue.h"
#include "Giver.h"
#include "StandsQue.h"
#include "Form1.h"

public ref class CCenter
{
public:
        CCenter();
        ~CCenter(void);
        void AddGiver(void);
        void Work(void);
        void AddStand(System::Int32 StandsNumber);
private:
        RCK::Form1 Interfejs;
};

Center.cpp

#include "StdAfx.h"
#include "Center.h"
#include "StandsQue.h"
#include "Form1.h"

CCenter::CCenter()
{
        //Interfejs.DocStands->Items->Add("1")->SubItems->Add("Udalo sie");
}

CCenter::~CCenter(void)
{
}

void CCenter::AddGiver(void)
{
}

void CCenter::Work(void)
{
}

void CCenter::AddStand(System::Int32 StandsNumber)
{
}

Someone can help ?

Recommended Answers

All 12 Replies

Have you tried taking out the (void) in the constructor for Form1 and instead using Form1() ?

I didn't know the compiler would accept non-pointer void arguments... it may be confusing it with a possible value? It's worth looking into..

and what i have to do ?

Just remove "Void"

from all of your functions.

CCenter::~CCenter(void)
{
}

change it to

CCenter::~CCenter()
{
}

And try if it works.

I made:

Form1.h

#pragma once
//#include "Center.h"
#include <time.h>
#include <windows.h>
ref class CCenter;

namespace RCK {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			CCenter^ Engine = gcnew CCenter();
			//
			//TODO: Add the constructor code here
			//
		}
...

Center.h

#pragma once
#include "StandsQue.h"
#include "Giver.h"
#include "StandsQue.h"
#include "Form1.h"

public ref class CCenter
{
public:
	CCenter(RCK::Form1^ inInterfejs);
	~CCenter();
	void AddGiver();
	void Work();
	void AddStand(System::Int32 StandsNumber);
private:
	RCK::Form1^ Interfejs;
};

Center.cpp

#include "StdAfx.h"
#include "Center.h"
#include "StandsQue.h"
#include "Form1.h"

CCenter::CCenter(RCK::Form1^ inInterfejs)
: Interfejs(nullptr)
{
	//Interfejs.DocStands->Items->Add("1")->SubItems->Add("Udalo sie");
}

CCenter::~CCenter()
{
}

void CCenter::AddGiver()
{
}

void CCenter::Work()
{
}

void CCenter::AddStand(System::Int32 StandsNumber)
{
}

and error is still :(

public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(/*void*/) //notice here that void is commented out... do that
		{
			InitializeComponent();
			CCenter^ Engine = gcnew CCenter();
			//
			//TODO: Add the constructor code here
			//
		}
...

I made this Form1(/*void*/) and problem is still ... ;( help !

You need to add a new .cpp file, e.g. Form1.cpp, in which you implement the Form1 class's constructor.

// Form1.cpp
#include "StdAfx.h"
#include "Center.h"  // include center.h to be able to construct a CCenter object
#include "Form1.h"

namespace RCK {

Form1::Form1(void)
{
    InitializeComponent(); 
    CCenter^ Engine = gcnew CCenter();
}
} // namespace RCK

In your Form1.h the constructor will be only declared...

public ref class Form1 : public System::Windows::Forms::Form
{
public:
	Form1(void); // constructor, implementation in Form1.cpp
...

I made this...

error still but now in Form1.cpp...... :(:(:( please help.. i need this program so fast...

I made this...

error still but now in Form1.cpp...... :(:(:( please help.. i need this program so fast...

What is the error?

1>.\Form1.cpp(10) : error C2512: 'CCenter::CCenter' : no appropriate default constructor available
1>.\Form1.cpp(10) : error C2512: 'CCenter::CCenter' : no appropriate default constructor available

I take that you have only the following constructor: CCenter(RCK::Form1^ inInterfejs); the following calls for the default constructor, which you don't have CCenter^ Engine = gcnew CCenter(); So you might add the default constructor

CCenter::CCenter()
{
    // initialize the object here ...
}

or use the existing constructor by calling CCenter^ Engine = gcnew CCenter( this );

Thanks!! It works!! I forgot to change in CCenter. Thank you!

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.