473,396 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

declare & initialize array?

Hello,

Can I separately declare and initialize a string array? How and where
would I do it in the code below? It was created using Visual C++ 2005
Express Beta 2 ...

In C# I would have

private string[] myArray;

and later

myArray = new string[] {"element 1","element 2"};

Now, I know C++ is more difficult to learn than C# but .......

Thanks

Geoff

#pragma once

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

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>
/// <param name="disposing">"description of the
parameter"</param>
virtual void Dispose(Boolean disposing) override
{
if (disposing && components)
{
delete components;
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::PictureBox^ pictureBox1;
protected:
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::TrackBar^ trackBar1;
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)
{

System::ComponentModel::ComponentResourceManager^ resources = (gcnew
System::ComponentModel::ComponentResourceManager(F orm1::typeid));
this->pictureBox1 = (gcnew
System::Windows::Forms::PictureBox());
this->button1 = (gcnew
System::Windows::Forms::Button());
this->label1 = (gcnew
System::Windows::Forms::Label());
this->label2 = (gcnew
System::Windows::Forms::Label());
this->trackBar1 = (gcnew
System::Windows::Forms::TrackBar());

(cli::safe_cast<System::ComponentModel::ISupportIn itialize^
(this->pictureBox1))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportIn itialize^(this->trackBar1))->BeginInit(); this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->Image =
(cli::safe_cast<System::Drawing::Image^(resources->GetObject(L"pictureBox1.Image"))); this->pictureBox1->Location =
System::Drawing::Point(36, 26);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size =
System::Drawing::Size(218, 129);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
//
// button1
//
this->button1->Location =
System::Drawing::Point(105, 231);
this->button1->Name = L"button1";
this->button1->Size =
System::Drawing::Size(75, 23);
this->button1->TabIndex = 1;
this->button1->Text = L"button1";
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location =
System::Drawing::Point(23, 190);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(31,
13);
this->label1->TabIndex = 2;
this->label1->Text = L"label1";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location =
System::Drawing::Point(222, 190);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(31,
13);
this->label2->TabIndex = 3;
this->label2->Text = L"label2";
//
// trackBar1
//
this->trackBar1->Location =
System::Drawing::Point(87, 180);
this->trackBar1->Name = L"trackBar1";
this->trackBar1->Size =
System::Drawing::Size(104, 45);
this->trackBar1->TabIndex = 4;
this->trackBar1->Scroll += gcnew
System::EventHandler(this, &Form1::Form1_Load);
//
// Form1
//
this->AutoScaleDimensions =
System::Drawing::SizeF(6, 13);
this->AutoScaleMode =
System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292,
266);
this->Controls->Add(this->trackBar1);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->button1);
this->Controls->Add(this->pictureBox1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this,
&Form1::Form1_Load);

(cli::safe_cast<System::ComponentModel::ISupportIn itialize^(this->pictureBox1))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportIn itialize^(this->trackBar1))->EndInit();

this->ResumeLayout(false);
this->PerformLayout();

}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender,
System::EventArgs^ e) {
}
};
}

Nov 17 '05 #1
15 5288
Hi Geoff!

Declare the array like

private: System::String __gc* myArray __gc[];

and initialize it anywhere you want like

this->myArray = new System::String* __gc[2];

this->myArray[0] = "element 1";

this->myArray[1] = "element 2";
Hope that helps!

- Markus
<Geoff Cox> schrieb im Newsbeitrag
news:bq********************************@4ax.com...
Hello,

Can I separately declare and initialize a string array? How and where
would I do it in the code below? It was created using Visual C++ 2005
Express Beta 2 ...

In C# I would have

private string[] myArray;

and later

myArray = new string[] {"element 1","element 2"};

Now, I know C++ is more difficult to learn than C# but .......

Thanks

Geoff

#pragma once

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

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>
/// <param name="disposing">"description of the
parameter"</param>
virtual void Dispose(Boolean disposing) override
{
if (disposing && components)
{
delete components;
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::PictureBox^ pictureBox1;
protected:
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::TrackBar^ trackBar1;
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)
{

System::ComponentModel::ComponentResourceManager^ resources = (gcnew
System::ComponentModel::ComponentResourceManager(F orm1::typeid));
this->pictureBox1 = (gcnew
System::Windows::Forms::PictureBox());
this->button1 = (gcnew
System::Windows::Forms::Button());
this->label1 = (gcnew
System::Windows::Forms::Label());
this->label2 = (gcnew
System::Windows::Forms::Label());
this->trackBar1 = (gcnew
System::Windows::Forms::TrackBar());

(cli::safe_cast<System::ComponentModel::ISupportIn itialize^
(this->pictureBox1))->BeginInit();


(cli::safe_cast<System::ComponentModel::ISupportIn itialize^
(this->trackBar1))->BeginInit();

this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->Image =
(cli::safe_cast<System::Drawing::Image^
(resources->GetObject(L"pictureBox1.Image")));

this->pictureBox1->Location =
System::Drawing::Point(36, 26);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size =
System::Drawing::Size(218, 129);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
//
// button1
//
this->button1->Location =
System::Drawing::Point(105, 231);
this->button1->Name = L"button1";
this->button1->Size =
System::Drawing::Size(75, 23);
this->button1->TabIndex = 1;
this->button1->Text = L"button1";
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location =
System::Drawing::Point(23, 190);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(31,
13);
this->label1->TabIndex = 2;
this->label1->Text = L"label1";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location =
System::Drawing::Point(222, 190);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(31,
13);
this->label2->TabIndex = 3;
this->label2->Text = L"label2";
//
// trackBar1
//
this->trackBar1->Location =
System::Drawing::Point(87, 180);
this->trackBar1->Name = L"trackBar1";
this->trackBar1->Size =
System::Drawing::Size(104, 45);
this->trackBar1->TabIndex = 4;
this->trackBar1->Scroll += gcnew
System::EventHandler(this, &Form1::Form1_Load);
//
// Form1
//
this->AutoScaleDimensions =
System::Drawing::SizeF(6, 13);
this->AutoScaleMode =
System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292,
266);
this->Controls->Add(this->trackBar1);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->button1);
this->Controls->Add(this->pictureBox1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this,
&Form1::Form1_Load);

(cli::safe_cast<System::ComponentModel::ISupportIn itialize^
(this->pictureBox1))->EndInit();


(cli::safe_cast<System::ComponentModel::ISupportIn itialize^
(this->trackBar1))->EndInit();

this->ResumeLayout(false);
this->PerformLayout();

}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender,
System::EventArgs^ e) {
}
};
}

Nov 17 '05 #2
<Geoff Cox> wrote in message
news:bq********************************@4ax.com...
Can I separately declare and initialize a string array? How and where
would I do it in the code below? It was created using Visual C++ 2005
Express Beta 2 ...

In C# I would have

private string[] myArray;

and later

myArray = new string[] {"element 1","element 2"};

Now, I know C++ is more difficult to learn than C# but .......


This is the VC.Net 2003 equivalent:

String *myArray[];

myArray = new String*[2];
myArray[0] = new String("element 1");
myArray[1] = new String("element 2");

I should tell you that I don't have 2005 installed on this box (where I have
a two C++ compiler limit <g>) but I think that to convert from MC++ to
C++/CLI all you have to do is to replace the *'s with ^'s and new's with
gcnew's

String ^myArray[];

myArray = new String^ [2];
myArray[0] = gcnew String("element 1");
myArray[1] = gcnew String("element 2");

Regards,
Will


Nov 17 '05 #3
Almost like in C#:

array<String^>^ myArray = gcnew array<String^> {"element 1",
"element 2"};

You can only do this in Visual C++ 2005, and only in .NET. It's a
completely new feature.

See: http://www.codeproject.com/managedcpp/cppcliarrays.asp

In standard C++ and old MC++ you can't initialize arrays. C++ doesn't
have the concept of array initialization.

Tom

Geoff Cox wrote:
Hello,

Can I separately declare and initialize a string array? How and where
would I do it in the code below? It was created using Visual C++ 2005
Express Beta 2 ...

In C# I would have

private string[] myArray;

and later

myArray = new string[] {"element 1","element 2"};

Now, I know C++ is more difficult to learn than C# but .......

Thanks

Geoff

Nov 17 '05 #4
Use the initializer syntax in C++CLI...

array<String^>^ myArray;
....
myArray= gcnew array<String^> {"first", "second"};

Willy.

<Geoff Cox> wrote in message
news:bq********************************@4ax.com...
Hello,

Can I separately declare and initialize a string array? How and where
would I do it in the code below? It was created using Visual C++ 2005
Express Beta 2 ...

In C# I would have

private string[] myArray;

and later

myArray = new string[] {"element 1","element 2"};

Now, I know C++ is more difficult to learn than C# but .......

Thanks

Geoff

#pragma once

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

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>
/// <param name="disposing">"description of the
parameter"</param>
virtual void Dispose(Boolean disposing) override
{
if (disposing && components)
{
delete components;
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::PictureBox^ pictureBox1;
protected:
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::TrackBar^ trackBar1;
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)
{

System::ComponentModel::ComponentResourceManager^ resources = (gcnew
System::ComponentModel::ComponentResourceManager(F orm1::typeid));
this->pictureBox1 = (gcnew
System::Windows::Forms::PictureBox());
this->button1 = (gcnew
System::Windows::Forms::Button());
this->label1 = (gcnew
System::Windows::Forms::Label());
this->label2 = (gcnew
System::Windows::Forms::Label());
this->trackBar1 = (gcnew
System::Windows::Forms::TrackBar());

(cli::safe_cast<System::ComponentModel::ISupportIn itialize^
(this->pictureBox1))->BeginInit();


(cli::safe_cast<System::ComponentModel::ISupportIn itialize^
(this->trackBar1))->BeginInit();

this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->Image =
(cli::safe_cast<System::Drawing::Image^
(resources->GetObject(L"pictureBox1.Image")));

this->pictureBox1->Location =
System::Drawing::Point(36, 26);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size =
System::Drawing::Size(218, 129);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
//
// button1
//
this->button1->Location =
System::Drawing::Point(105, 231);
this->button1->Name = L"button1";
this->button1->Size =
System::Drawing::Size(75, 23);
this->button1->TabIndex = 1;
this->button1->Text = L"button1";
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location =
System::Drawing::Point(23, 190);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(31,
13);
this->label1->TabIndex = 2;
this->label1->Text = L"label1";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location =
System::Drawing::Point(222, 190);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(31,
13);
this->label2->TabIndex = 3;
this->label2->Text = L"label2";
//
// trackBar1
//
this->trackBar1->Location =
System::Drawing::Point(87, 180);
this->trackBar1->Name = L"trackBar1";
this->trackBar1->Size =
System::Drawing::Size(104, 45);
this->trackBar1->TabIndex = 4;
this->trackBar1->Scroll += gcnew
System::EventHandler(this, &Form1::Form1_Load);
//
// Form1
//
this->AutoScaleDimensions =
System::Drawing::SizeF(6, 13);
this->AutoScaleMode =
System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292,
266);
this->Controls->Add(this->trackBar1);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->button1);
this->Controls->Add(this->pictureBox1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this,
&Form1::Form1_Load);

(cli::safe_cast<System::ComponentModel::ISupportIn itialize^
(this->pictureBox1))->EndInit();


(cli::safe_cast<System::ComponentModel::ISupportIn itialize^
(this->trackBar1))->EndInit();

this->ResumeLayout(false);
this->PerformLayout();

}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender,
System::EventArgs^ e) {
}
};
}

Nov 17 '05 #5
On Tue, 16 Aug 2005 22:37:01 +0200, "Markus Minichmayr"
<ne*******@hotmail.com> wrote:
Hi Geoff!

Declare the array like

private: System::String __gc* myArray __gc[];

and initialize it anywhere you want like

this->myArray = new System::String* __gc[2];

this->myArray[0] = "element 1";

this->myArray[1] = "element 2";
Markus,

Thanks for the help. I have used as above in code below but am getting
a lot of errors.

Errors first and code after that. Any thoughts?! Have I declared the
arrays in the wrong place? Rememeber I am using Visual C++ 2005
Express Beta 2 - this relevant?

Cheers

Geoff

-------------errors------------------

Compiling...
stdafx.cpp
Compiling...
slider1.cpp
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(60) : error C4980: '__gc' : use
of this keyword requires /clr:oldSyntax command line option
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(60) : error C3699:
'interior_ptr' : cannot use this indirection on type 'System::String'
compiler replacing 'interior_ptr' with '^' to continue parsing
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(60) : error C2728:
'System::String ^' : a native array cannot contain this managed type
Did you mean 'array'?
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(61) : error C3699:
'interior_ptr' : cannot use this indirection on type 'System::String'
compiler replacing 'interior_ptr' with '^' to continue parsing
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(61) : error C2728:
'System::String ^' : a native array cannot contain this managed type
Did you mean 'array'?
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(62) : error C3699:
'interior_ptr' : cannot use this indirection on type 'System::String'
compiler replacing 'interior_ptr' with '^' to continue parsing
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(62) : error C2728:
'System::String ^' : a native array cannot contain this managed type
Did you mean 'array'?
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(64) : error C2059: syntax error
: 'this'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(64) : error C3150: '[' : '__gc'
can only be applied to a class, struct, interface, array or pointer
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(64) : error C2143: syntax error
: missing ')' before '}'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(64) : error C2143: syntax error
: missing ';' before '}'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(64) : error C2238: unexpected
token(s) preceding ';'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(60) : error C4368: cannot define
'LHSquestions' as a member of managed 'slider1::Form1': mixed types
are not supported
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(61) : error C4368: cannot define
'RHSquestions' as a member of managed 'slider1::Form1': mixed types
are not supported
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(62) : error C4368: cannot define
'results' as a member of managed 'slider1::Form1': mixed types are not
supported
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(65) : error C2143: syntax error
: missing ';' before 'this'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(27) : error C2059: syntax error
: 'this'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(27) : error C2143: syntax error
: missing ';' before '{'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(27) : error C2447: '{' : missing
function header (old-style formal list?)
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(47) : error C2065: 'components'
: undeclared identifier
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(49) : error C2541: 'delete' :
cannot delete objects that are not pointers
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(65) : error C2059: syntax error
: '->'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(65) : error C3150: '[' : '__gc'
can only be applied to a class, struct, interface, array or pointer
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(65) : error C2143: syntax error
: missing ')' before '}'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(65) : error C2143: syntax error
: missing ';' before '}'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(66) : error C2059: syntax error
: 'this'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(67) : error C2059: syntax error
: 'this'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(68) : error C2059: syntax error
: 'this'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(69) : error C2059: syntax error
: 'this'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(76) : error C3145: 'components'
: global or static variable may not have managed type
'System::ComponentModel::Container ^'
may not declare a global or static variable, or a member of a
native type that refers to objects in the gc heap
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(76) : error C2373: 'components'
: redefinition; different type modifiers
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(85) : error C2653: 'Form1' : is
not a class or namespace name
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(85) : fatal error C1903: unable
to recover from previous error(s); stopping compilation
AssemblyInfo.cpp
Generating Code...


---------code-------------------

#pragma once
namespace slider1
{
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
//
// this.label1.Text = LHSquestions[qnumber];
// this.label2.Text = RHSquestions[qnumber];

}

protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">"description of the
parameter"</param>
virtual void Dispose(Boolean disposing) override
{
if (disposing && components)
{
delete components;
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::PictureBox^ pictureBox1;
protected:
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::TrackBar^ trackBar1;

private: System::String __gc* LHSquestions __gc[];
private: System::String __gc* RHSquestions __gc[];
private: System::String __gc* results __gc[];

this->LHSquestions = new System::String* __gc[2}
this->RHSquestions = new System::String* __gc[2}
this->LHSquestions[0] = "question 1";
this->LHSquestions[1] = "question 2";
this->RHSquestions[0] = "question 1";
this->RHSquestions[1] = "question 2";

/// <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)
{

System::ComponentModel::ComponentResourceManager^ resources = (gcnew
System::ComponentModel::ComponentResourceManager(F orm1::typeid));
this->pictureBox1 = (gcnew
System::Windows::Forms::PictureBox());
this->button1 = (gcnew
System::Windows::Forms::Button());
this->label1 = (gcnew
System::Windows::Forms::Label());
this->label2 = (gcnew
System::Windows::Forms::Label());
this->trackBar1 = (gcnew
System::Windows::Forms::TrackBar());

(cli::safe_cast<System::ComponentModel::ISupportIn itialize^(this->pictureBox1))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportIn itialize^(this->trackBar1))->BeginInit(); this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->Image =
(cli::safe_cast<System::Drawing::Image^(resources->GetObject(L"pictureBox1.Image"))); this->pictureBox1->Location =
System::Drawing::Point(36, 26);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size =
System::Drawing::Size(218, 129);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
//
// button1
//
this->button1->Location =
System::Drawing::Point(105, 231);
this->button1->Name = L"button1";
this->button1->Size =
System::Drawing::Size(75, 23);
this->button1->TabIndex = 1;
this->button1->Text = L"NEXT";
this->button1->Click += gcnew
System::EventHandler(this, &Form1::Form1_Load);
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location =
System::Drawing::Point(23, 190);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(31,
13);
this->label1->TabIndex = 2;
this->label1->Text = L"label1";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location =
System::Drawing::Point(222, 190);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(31,
13);
this->label2->TabIndex = 3;
this->label2->Text = L"label2";
//
// trackBar1
//
this->trackBar1->Location =
System::Drawing::Point(87, 180);
this->trackBar1->Name = L"trackBar1";
this->trackBar1->Size =
System::Drawing::Size(104, 45);
this->trackBar1->TabIndex = 4;
this->trackBar1->Scroll += gcnew
System::EventHandler(this, &Form1::Form1_Load);
//
// Form1
//
this->AutoScaleDimensions =
System::Drawing::SizeF(6, 13);
this->AutoScaleMode =
System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292,
266);
this->Controls->Add(this->trackBar1);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->button1);
this->Controls->Add(this->pictureBox1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this,
&Form1::Form1_Load);

(cli::safe_cast<System::ComponentModel::ISupportIn itialize^(this->pictureBox1))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportIn itialize^(this->trackBar1))->EndInit();

this->ResumeLayout(false);
this->PerformLayout();

}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender,
System::EventArgs^ e) {
}
};
}


Nov 17 '05 #6
On Tue, 16 Aug 2005 22:56:19 +0200, "Willy Denoyette [MVP]"
<wi*************@telenet.be> wrote:
Use the initializer syntax in C++CLI...

array<String^>^ myArray;
...
myArray= gcnew array<String^> {"first", "second"};


Thanks Willy - I'm moving on a little! I have used

private: array<String^>^ LHSquestions;
private: array<String^>^ RHSquestions;

line 60 LHSquestions = gcnew array<String^> {"question 1", "question
2"};
line 61 RHSquestions = gcnew array<String^> {"question 1", "question
2"};

but get following errors

Form1.h(60) : error C4430: missing type specifier - int assumed. Note:
C++ does not support default-int
Form1.h(60) : error C3845: 'slider1::Form1::LHSquestions': only static
data members can be initialized inside a ref class or value type

Form1.h(61) : error C4430: missing type specifier - int assumed. Note:
C++ does not support default-int
Form1.h(61) : error C3845: 'slider1::Form1::RHSquestions': only static
data members can be initialized inside a ref class or value type

any thoughts?

Cheers

Geoff


Nov 17 '05 #7
On Tue, 16 Aug 2005 13:49:15 -0700, Tamas Demjen <td*****@yahoo.com>
wrote:
Almost like in C#:

array<String^>^ myArray = gcnew array<String^> {"element 1",
"element 2"};


Thanks - could build OK with above but get error message with

array<String^>^ myArray;
....
myArray= gcnew array<String^> {"first", "second"};
error message

++ does not support default-int
Form1.h(60) : error C3845: 'slider1::Form1::LHSquestions': only static
data members can be initialized inside a ref class or value type

Form1.h(61) : error C4430: missing type specifier - int assumed. Note:
C++ does not support default-int
Form1.h(61) : error C3845: 'slider1::Form1::RHSquestions': only static
data members can be initialized inside a ref class or value type

any thoughts?

Cheers

Geoff



Nov 17 '05 #8
Sorry, I missed the point that you are using VC++ 2005. :-/

<Geoff Cox> schrieb im Newsbeitrag
news:lv********************************@4ax.com...
On Tue, 16 Aug 2005 22:37:01 +0200, "Markus Minichmayr"
<ne*******@hotmail.com> wrote:
Hi Geoff!

Declare the array like

private: System::String __gc* myArray __gc[];

and initialize it anywhere you want like

this->myArray = new System::String* __gc[2];

this->myArray[0] = "element 1";

this->myArray[1] = "element 2";


Markus,

Thanks for the help. I have used as above in code below but am getting
a lot of errors.

Errors first and code after that. Any thoughts?! Have I declared the
arrays in the wrong place? Rememeber I am using Visual C++ 2005
Express Beta 2 - this relevant?

Cheers

Geoff

-------------errors------------------

Compiling...
stdafx.cpp
Compiling...
slider1.cpp
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(60) : error C4980: '__gc' : use
of this keyword requires /clr:oldSyntax command line option
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(60) : error C3699:
'interior_ptr' : cannot use this indirection on type 'System::String'
compiler replacing 'interior_ptr' with '^' to continue parsing
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(60) : error C2728:
'System::String ^' : a native array cannot contain this managed type
Did you mean 'array'?
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(61) : error C3699:
'interior_ptr' : cannot use this indirection on type 'System::String'
compiler replacing 'interior_ptr' with '^' to continue parsing
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(61) : error C2728:
'System::String ^' : a native array cannot contain this managed type
Did you mean 'array'?
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(62) : error C3699:
'interior_ptr' : cannot use this indirection on type 'System::String'
compiler replacing 'interior_ptr' with '^' to continue parsing
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(62) : error C2728:
'System::String ^' : a native array cannot contain this managed type
Did you mean 'array'?
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(64) : error C2059: syntax error
: 'this'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(64) : error C3150: '[' : '__gc'
can only be applied to a class, struct, interface, array or pointer
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(64) : error C2143: syntax error
: missing ')' before '}'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(64) : error C2143: syntax error
: missing ';' before '}'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(64) : error C2238: unexpected
token(s) preceding ';'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(60) : error C4368: cannot define
'LHSquestions' as a member of managed 'slider1::Form1': mixed types
are not supported
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(61) : error C4368: cannot define
'RHSquestions' as a member of managed 'slider1::Form1': mixed types
are not supported
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(62) : error C4368: cannot define
'results' as a member of managed 'slider1::Form1': mixed types are not
supported
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(65) : error C2143: syntax error
: missing ';' before 'this'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(27) : error C2059: syntax error
: 'this'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(27) : error C2143: syntax error
: missing ';' before '{'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(27) : error C2447: '{' : missing
function header (old-style formal list?)
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(47) : error C2065: 'components'
: undeclared identifier
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(49) : error C2541: 'delete' :
cannot delete objects that are not pointers
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(65) : error C2059: syntax error
: '->'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(65) : error C3150: '[' : '__gc'
can only be applied to a class, struct, interface, array or pointer
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(65) : error C2143: syntax error
: missing ')' before '}'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(65) : error C2143: syntax error
: missing ';' before '}'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(66) : error C2059: syntax error
: 'this'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(67) : error C2059: syntax error
: 'this'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(68) : error C2059: syntax error
: 'this'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(69) : error C2059: syntax error
: 'this'
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(76) : error C3145: 'components'
: global or static variable may not have managed type
'System::ComponentModel::Container ^'
may not declare a global or static variable, or a member of a
native type that refers to objects in the gc heap
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(76) : error C2373: 'components'
: redefinition; different type modifiers
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(85) : error C2653: 'Form1' : is
not a class or namespace name
d:\documents and settings\administrator\my documents\visual studio
2005\projects\slider1\slider1\Form1.h(85) : fatal error C1903: unable
to recover from previous error(s); stopping compilation
AssemblyInfo.cpp
Generating Code...


---------code-------------------

#pragma once
namespace slider1
{
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
//
// this.label1.Text = LHSquestions[qnumber];
// this.label2.Text = RHSquestions[qnumber];

}

protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">"description of the
parameter"</param>
virtual void Dispose(Boolean disposing) override
{
if (disposing && components)
{
delete components;
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::PictureBox^ pictureBox1;
protected:
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::TrackBar^ trackBar1;

private: System::String __gc* LHSquestions __gc[];
private: System::String __gc* RHSquestions __gc[];
private: System::String __gc* results __gc[];

this->LHSquestions = new System::String* __gc[2}
this->RHSquestions = new System::String* __gc[2}
this->LHSquestions[0] = "question 1";
this->LHSquestions[1] = "question 2";
this->RHSquestions[0] = "question 1";
this->RHSquestions[1] = "question 2";

/// <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)
{

System::ComponentModel::ComponentResourceManager^ resources = (gcnew
System::ComponentModel::ComponentResourceManager(F orm1::typeid));
this->pictureBox1 = (gcnew
System::Windows::Forms::PictureBox());
this->button1 = (gcnew
System::Windows::Forms::Button());
this->label1 = (gcnew
System::Windows::Forms::Label());
this->label2 = (gcnew
System::Windows::Forms::Label());
this->trackBar1 = (gcnew
System::Windows::Forms::TrackBar());

(cli::safe_cast<System::ComponentModel::ISupportIn itialize^
(this->pictureBox1))->BeginInit();


(cli::safe_cast<System::ComponentModel::ISupportIn itialize^
(this->trackBar1))->BeginInit();

this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->Image =
(cli::safe_cast<System::Drawing::Image^
(resources->GetObject(L"pictureBox1.Image")));

this->pictureBox1->Location =
System::Drawing::Point(36, 26);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size =
System::Drawing::Size(218, 129);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
//
// button1
//
this->button1->Location =
System::Drawing::Point(105, 231);
this->button1->Name = L"button1";
this->button1->Size =
System::Drawing::Size(75, 23);
this->button1->TabIndex = 1;
this->button1->Text = L"NEXT";
this->button1->Click += gcnew
System::EventHandler(this, &Form1::Form1_Load);
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location =
System::Drawing::Point(23, 190);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(31,
13);
this->label1->TabIndex = 2;
this->label1->Text = L"label1";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location =
System::Drawing::Point(222, 190);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(31,
13);
this->label2->TabIndex = 3;
this->label2->Text = L"label2";
//
// trackBar1
//
this->trackBar1->Location =
System::Drawing::Point(87, 180);
this->trackBar1->Name = L"trackBar1";
this->trackBar1->Size =
System::Drawing::Size(104, 45);
this->trackBar1->TabIndex = 4;
this->trackBar1->Scroll += gcnew
System::EventHandler(this, &Form1::Form1_Load);
//
// Form1
//
this->AutoScaleDimensions =
System::Drawing::SizeF(6, 13);
this->AutoScaleMode =
System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292,
266);
this->Controls->Add(this->trackBar1);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->button1);
this->Controls->Add(this->pictureBox1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this,
&Form1::Form1_Load);

(cli::safe_cast<System::ComponentModel::ISupportIn itialize^
(this->pictureBox1))->EndInit();


(cli::safe_cast<System::ComponentModel::ISupportIn itialize^
(this->trackBar1))->EndInit();

this->ResumeLayout(false);
this->PerformLayout();

}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender,
System::EventArgs^ e) {
}
};
}


Nov 17 '05 #9
On Wed, 17 Aug 2005 10:12:12 +0200, "Markus Minichmayr"
<ne*******@hotmail.com> wrote:
Sorry, I missed the point that you are using VC++ 2005. :-/


No problem! Wonder if you can comment on my postings to Tamas and
Willy? I am not clear where I should place the initialization of the
arrays...

Geoff

Nov 17 '05 #10
On Wed, 17 Aug 2005 10:12:12 +0200, "Markus Minichmayr"
<ne*******@hotmail.com> wrote:
Sorry, I missed the point that you are using VC++ 2005. :-/


No problem! Wonder if you can comment on my postings to Tamas and
Willy? I am not clear where I should place the initialization of the
arrays...

Geoff

Nov 17 '05 #11
Weird, It looks like your LHSquestions and RHSquestions declarations are not
visible by the initializers ( = gcnew array<String^> {"question 1).....
Could you post all of the code (just strip the non relevant parts).

Willy.

<Geoff Cox> wrote in message
news:v7********************************@4ax.com...
On Tue, 16 Aug 2005 22:56:19 +0200, "Willy Denoyette [MVP]"
<wi*************@telenet.be> wrote:
Use the initializer syntax in C++CLI...

array<String^>^ myArray;
...
myArray= gcnew array<String^> {"first", "second"};


Thanks Willy - I'm moving on a little! I have used

private: array<String^>^ LHSquestions;
private: array<String^>^ RHSquestions;

line 60 LHSquestions = gcnew array<String^> {"question 1", "question
2"};
line 61 RHSquestions = gcnew array<String^> {"question 1", "question
2"};

but get following errors

Form1.h(60) : error C4430: missing type specifier - int assumed. Note:
C++ does not support default-int
Form1.h(60) : error C3845: 'slider1::Form1::LHSquestions': only static
data members can be initialized inside a ref class or value type

Form1.h(61) : error C4430: missing type specifier - int assumed. Note:
C++ does not support default-int
Form1.h(61) : error C3845: 'slider1::Form1::RHSquestions': only static
data members can be initialized inside a ref class or value type

any thoughts?

Cheers

Geoff


Nov 17 '05 #12
On Wed, 17 Aug 2005 11:19:06 +0200, "Willy Denoyette [MVP]"
<wi*************@telenet.be> wrote:
Weird, It looks like your LHSquestions and RHSquestions declarations are not
visible by the initializers ( = gcnew array<String^> {"question 1).....
Could you post all of the code (just strip the non relevant parts).


Willy

I have got it building OK with the code below, ie putting the
declarations/initializations with the others, but, I cannot see
how/where to declare/initialize an int qnumber which would be used as
the array index ...

eg

int qnumber = 0;

to be used in

LHSquestions[qnumber]

How would I do this?

Cheers

Geoff
#pragma once
namespace trackbar1
{
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
//
private: int qnumber = 0;
this->label1->Text = LHSquestions[qnumber];
this->label2->Text = RHSquestions[qnumber];
}

protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">"description of the
parameter"</param>
virtual void Dispose(Boolean disposing) override
{
if (disposing && components)
{
delete components;
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::TrackBar^ trackBar1;
protected:
private: System::Windows::Forms::PictureBox^ pictureBox1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Button^ button1;

private: static array<String^>^ LHSquestions = gcnew
array<String^> {"question 1", "question 2"};
private: static array<String^>^ RHSquestions = gcnew
array<String^> {"question 1", "question 2"};

Nov 17 '05 #13
Geoff Cox wrote:
Form1.h(60) : error C3845: 'slider1::Form1::LHSquestions': only static
data members can be initialized inside a ref class or value type


Is it possible that you're initializing variables in the class
declaration? Just like in C++, C++/CLI can't do that either. You must
initialize member variables in your c'tor:

ref class C
{
C();
int i;
array<String^>^ myArray;
};

C::C()
: i(0), myArray(gcnew array<String^> {"first", "second"})
{
}

or

C::C()
{
i = 0;
myArray = gcnew array<String^> {"first", "second"};
}

Tom
Nov 17 '05 #14
On Wed, 17 Aug 2005 10:40:46 -0700, Tamas Demjen <td*****@yahoo.com>
wrote:
Geoff Cox wrote:
Form1.h(60) : error C3845: 'slider1::Form1::LHSquestions': only static
data members can be initialized inside a ref class or value type
Is it possible that you're initializing variables in the class
declaration? Just like in C++, C++/CLI can't do that either. You must
initialize member variables in your c'tor:


could well be the case but what is c'tor?!

Geoff


ref class C
{
C();
int i;
array<String^>^ myArray;
};

C::C()
: i(0), myArray(gcnew array<String^> {"first", "second"})
{
}

or

C::C()
{
i = 0;
myArray = gcnew array<String^> {"first", "second"};
}

Tom


Nov 17 '05 #15
On Wed, 17 Aug 2005 10:40:46 -0700, Tamas Demjen <td*****@yahoo.com>
wrote:
Geoff Cox wrote:
Form1.h(60) : error C3845: 'slider1::Form1::LHSquestions': only static
data members can be initialized inside a ref class or value type
Is it possible that you're initializing variables in the class
declaration? Just like in C++, C++/CLI can't do that either. You must
initialize member variables in your c'tor:


got it ! constructor?

Geoff



ref class C
{
C();
int i;
array<String^>^ myArray;
};

C::C()
: i(0), myArray(gcnew array<String^> {"first", "second"})
{
}

or

C::C()
{
i = 0;
myArray = gcnew array<String^> {"first", "second"};
}

Tom


Nov 17 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mackan | last post by:
Hi! I'm trying to declare a structure that will be including pointers to functions. These structures in turn will be pointed to in an array and depending on a index value that specific function...
3
by: Ling Chen Wu | last post by:
Hi, I need to call a dll function but have no idea how to declare the function in VB.NET In the .h file, it is declare as follows: int CALLBACK gscBsiGcReadTagList( IN ...
10
by: utab | last post by:
Dear all, Can somebody direct me to some resources on the subject or explain the details in brief? I checked the FAQ but could not find or maybe missed. Regards,
11
by: toton | last post by:
Hi, I have little confusion about static memory allocation & dynamic allocation for a cluss member. I have class like class Bar{ public: explicit Bar(){ cout<<"bar default"<<endl; }
2
by: freegnu | last post by:
how to declare a friend function that can access two class it will look like the following class A { private: int i; public: A(){} ~A(){} friend void call(A &a, B &b);
2
by: juan.gautier | last post by:
Hi, I try to construct a SQL code for a view to select a specific data from a table, this query take the value of the filter from a text box in a visual basic 6.0 form. my problem is when i...
3
by: johnmmcparland | last post by:
Hi all, I would like to have a static constant array inside a class definition which would contain the number of days in each month (I am writing a Date class as an exercise). However my...
8
by: M.Endraszka | last post by:
Hi, I am writing a simple irc-like server and came across weird behavior while debugging. Could anyone tell me why the following happens : I have a class which stores pipe descriptors as a...
3
by: Ramesh | last post by:
Hi, I am trying to create an array of pointers to member functions inside my class. When I created a global array of type pfn & initialized with member functions and copy it back to the member...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.