missing constructor???

Hi,

I have serious trouble with default constructor in CLR/CLI Windows Forms - Managed C++.

Compiler said me: "no appropriate default constructor available"


Error is on row:

CLRW2:: SData^ ptrSData = gcnew SData();

in method:

System::Void Form1_Load

Default constructor is in :

ref class SData : public System::Object

I tried to change "gcnew SData();" to "gcnew SData;"
but without effect.

Can anybody help me? Where is problem?



See code:




==================================================
CLRW2.cpp
==================================================

// CLRW2.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"

using namespace CLRW2;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);

// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}


==================================================
Form1.h
==================================================

#pragma once


namespace CLRW2 {

ref class SData;
ref class Form1;

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();
//
//TODO: Add the constructor code here
//
}

protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}

protected:

private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel:: Container ^components;

#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->SuspendLayout();
//
// Form1
//
this->AutoScaleDimensions = System:: Drawing:: SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System:: Drawing:: Size(478, 310);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System:: EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);

}
#pragma endregion

private: System:: Void Form1_Load(System:: Object^ sender, System::EventArgs^ e) {
CLRW2:: SData^ ptrSData = gcnew CLRW2:: SData();
}
};

ref class SData : public System::Object
{

public :
SData() {}

}; // public ref class SourceData : public System::Object

}




Last edited on
Try

public ref class SData

and there is no need to derive from System::Object, as all objects in .NET already do.
I thing "Danielm103" is not so clever as he "look like". :-)
His answer is not true.
closed account (z05DSL3A)
Put your definition of SData before Form1
Form1.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once

namespace CLRW2 {

ref class SData
{
public :
    SData(){}

}; // public ref class SourceData : public System::Object

ref class Form1;

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();
//
//TODO: Add the constructor code here
//
}

protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}

protected: 

private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel:: Container ^components;

#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->SuspendLayout();
// 
// Form1
// 
this->AutoScaleDimensions = System:: Drawing:: SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System:: Drawing:: Size(478, 310);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System:: EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);

}
#pragma endregion

private: System:: Void Form1_Load(System:: Object^ sender, System::EventArgs^ e) {
CLRW2::SData^ ptrSData = gcnew CLRW2::SData();
}
};
}
Last edited on
I’ve been told that I don’t look that smart before : -)
thanks Grey Wolf
Do not worry dear boys (or girls) Danielm103 and Grey Wolf, do not be angry too, but if I use your advice(opinion) I am not able to use Designer. Designer said me, it is not able to find "ref class Form1;"

Newer mind.

I have
MS Visual studio 2008, version 9.0.30729.1SP, .NET 3.5
It is highly probably, I have a bad version of Visual studio.

:-)

Do you "anybody" know "stdafx.h" ?
I would like to know, why did you to adviced me badly?
It does nto sense.

closed account (z05DSL3A)
Well, in that case create a header file for your SData class and include it in the stdafx header.


1
2
3
4
5
6
7
8
namespace CLRW2 {
public ref class SData
{
public :
    SData(){}

}; // public ref class SourceData : public System::Object
}
data.h


1
2
3
4
5
6
7
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
#pragma once

// TODO: reference additional headers your program requires here
#include "data.h" 
stdafx.h


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#pragma once

namespace CLRW2 {


ref class Form1;

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();
...
form1.h


I would like to know, why did you to adviced me badly?

If I knew you had...never mind.

Dear girls Danielm103 and Grey Wolf (or boys?).
Your last reply seems to be OK.
But, a right programmer boy is clever evrythime.
Not in "Mar 31, 2009 at 8:35pm" only. :-)

I thing the right big programmers died-off. :-(

"DE::Das ist abër Schade."
closed account (z05DSL3A)
JerryMouse, insulting people is not a good way to illicit help.

I wish you all the luck getting help in the future...and suggest you give adequate information to get to your required solution.
Yes, you true. I am sorry. But, try to understand.
If you know, that your advice is not right, it is not fair-play to give an advice to someone.

Jerry
@JerryMouse: That is like stating that if an English teacher accidentally misspells discombobulated then they are obviously not an English teacher.
Topic archived. No new replies allowed.