473,507 Members | 2,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

where to place array initialization?

Hello,

I am trying to get a grip on where to place the initialization of two
arrays in the code below which was created using Visual C++ 2005
Express Beta 2...

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

I had assumed that I would add them after the other private lines
below? Any suggestions for a beginner's Internet tutorial or book on
using C++ Express language?

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
//
}

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:
/// <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->trackBar1 = (gcnew
System::Windows::Forms::TrackBar());
this->pictureBox1 = (gcnew
System::Windows::Forms::PictureBox());
this->label1 = (gcnew
System::Windows::Forms::Label());
this->label2 = (gcnew
System::Windows::Forms::Label());
this->button1 = (gcnew
System::Windows::Forms::Button());

(cli::safe_cast<System::ComponentModel::ISupportIn itialize^
(this->trackBar1))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportIn itialize^(this->pictureBox1))->BeginInit(); this->SuspendLayout();
//
// trackBar1
//
this->trackBar1->Location =
System::Drawing::Point(90, 168);
this->trackBar1->Name = L"trackBar1";
this->trackBar1->Size =
System::Drawing::Size(104, 45);
this->trackBar1->TabIndex = 0;
//
// pictureBox1
//
this->pictureBox1->Image =
(cli::safe_cast<System::Drawing::Image^(resources->GetObject(L"pictureBox1.Image"))); this->pictureBox1->Location =
System::Drawing::Point(37, 13);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size =
System::Drawing::Size(212, 134);
this->pictureBox1->TabIndex = 1;
this->pictureBox1->TabStop = false;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location =
System::Drawing::Point(27, 182);
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(230, 182);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(31,
13);
this->label2->TabIndex = 3;
this->label2->Text = L"label2";
//
// button1
//
this->button1->Location =
System::Drawing::Point(100, 219);
this->button1->Name = L"button1";
this->button1->Size =
System::Drawing::Size(75, 23);
this->button1->TabIndex = 4;
this->button1->Text = L"NEXT";
//
// 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->button1);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->pictureBox1);
this->Controls->Add(this->trackBar1);
this->Name = L"Form1";
this->Text = L"Form1";

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

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

}
#pragma endregion
};
}

Nov 17 '05 #1
11 2243
It's a matter of style I guess.
One option - You could put all your static array members together.

Also note that you don't need to specify "private" for each declaration. One
would do.

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

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com
<Geoff Cox> wrote in message
news:lu********************************@4ax.com...
Hello,

I am trying to get a grip on where to place the initialization of two
arrays in the code below which was created using Visual C++ 2005
Express Beta 2...

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

I had assumed that I would add them after the other private lines
below? Any suggestions for a beginner's Internet tutorial or book on
using C++ Express language?

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
//
}

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:
/// <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->trackBar1 = (gcnew
System::Windows::Forms::TrackBar());
this->pictureBox1 = (gcnew
System::Windows::Forms::PictureBox());
this->label1 = (gcnew
System::Windows::Forms::Label());
this->label2 = (gcnew
System::Windows::Forms::Label());
this->button1 = (gcnew
System::Windows::Forms::Button());

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


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

this->SuspendLayout();
//
// trackBar1
//
this->trackBar1->Location =
System::Drawing::Point(90, 168);
this->trackBar1->Name = L"trackBar1";
this->trackBar1->Size =
System::Drawing::Size(104, 45);
this->trackBar1->TabIndex = 0;
//
// pictureBox1
//
this->pictureBox1->Image =
(cli::safe_cast<System::Drawing::Image^
(resources->GetObject(L"pictureBox1.Image")));

this->pictureBox1->Location =
System::Drawing::Point(37, 13);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size =
System::Drawing::Size(212, 134);
this->pictureBox1->TabIndex = 1;
this->pictureBox1->TabStop = false;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location =
System::Drawing::Point(27, 182);
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(230, 182);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(31,
13);
this->label2->TabIndex = 3;
this->label2->Text = L"label2";
//
// button1
//
this->button1->Location =
System::Drawing::Point(100, 219);
this->button1->Name = L"button1";
this->button1->Size =
System::Drawing::Size(75, 23);
this->button1->TabIndex = 4;
this->button1->Text = L"NEXT";
//
// 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->button1);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->pictureBox1);
this->Controls->Add(this->trackBar1);
this->Name = L"Form1";
this->Text = L"Form1";

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


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

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

}
#pragma endregion
};
}

Nov 17 '05 #2
On Wed, 17 Aug 2005 14:31:06 +0530, "Nishant Sivakumar"
<ni**@nospam.asianetindia.com> wrote:
It's a matter of style I guess.
Nish,

Not if you are as much of a C++ beginner as I am! I have found that if
I put them as below the build works. I cannot workout how to
declare/initialize an int called qnumber so that I can have

LHSquestions[qnumber]

How do I do this? Where would I put something like

private: int qnumber = 0;

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

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"};

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->trackBar1 = (gcnew
System::Windows::Forms::TrackBar());
this->pictureBox1 = (gcnew
System::Windows::Forms::PictureBox());
this->label1 = (gcnew
System::Windows::Forms::Label());
this->label2 = (gcnew
System::Windows::Forms::Label());
this->button1 = (gcnew
System::Windows::Forms::Button());

(cli::safe_cast<System::ComponentModel::ISupportIn itialize^(this->trackBar1))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportIn itialize^(this->pictureBox1))->BeginInit(); this->SuspendLayout();
//
// trackBar1
//
this->trackBar1->Location =
System::Drawing::Point(90, 168);
this->trackBar1->Name = L"trackBar1";
this->trackBar1->Size =
System::Drawing::Size(104, 45);
this->trackBar1->TabIndex = 0;
this->trackBar1->Scroll += gcnew
System::EventHandler(this, &Form1::trackBar1_Scroll);
//
// pictureBox1
//
this->pictureBox1->Image =
(cli::safe_cast<System::Drawing::Image^(resources->GetObject(L"pictureBox1.Image"))); this->pictureBox1->Location =
System::Drawing::Point(37, 13);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size =
System::Drawing::Size(212, 134);
this->pictureBox1->TabIndex = 1;
this->pictureBox1->TabStop = false;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location =
System::Drawing::Point(27, 182);
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(230, 182);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(31,
13);
this->label2->TabIndex = 3;
this->label2->Text = L"label2";
//
// button1
//
this->button1->Location =
System::Drawing::Point(100, 219);
this->button1->Name = L"button1";
this->button1->Size =
System::Drawing::Size(75, 23);
this->button1->TabIndex = 4;
this->button1->Text = L"NEXT";
this->button1->Click += gcnew
System::EventHandler(this, &Form1::button1_Click);
//
// 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->button1);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->pictureBox1);
this->Controls->Add(this->trackBar1);
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->trackBar1))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportIn itialize^(this->pictureBox1))->EndInit(); this->ResumeLayout(false);
this->PerformLayout();

}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e) {
++qnumber;
this->label1->Text = LHSquestions[qnumber];
this->label2->Text = RHSquestions[qnumber];
}
private: System::Void trackBar1_Scroll(System::Object^ sender,
System::EventArgs^ e) {
}

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


One option - You could put all your static array members together.

Also note that you don't need to specify "private" for each declaration. One
would do.

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


Nov 17 '05 #3
> Not if you are as much of a C++ beginner as I am! I have found that if
I put them as below the build works. I cannot workout how to
declare/initialize an int called qnumber so that I can have

LHSquestions[qnumber]

How do I do this? Where would I put something like

private: int qnumber = 0;
You cannot initialize a non-static member. Either make it static (if it
suites your purpose) or use an initialization list.
E.g. :-

ref class Test
{
private:
static int count = 10;
int x;
public:
Test():x(10)
{
}
};

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com
<Geoff Cox> wrote in message
news:lo********************************@4ax.com... On Wed, 17 Aug 2005 14:31:06 +0530, "Nishant Sivakumar"
<ni**@nospam.asianetindia.com> wrote:
It's a matter of style I guess.


Nish,

Not if you are as much of a C++ beginner as I am! I have found that if
I put them as below the build works. I cannot workout how to
declare/initialize an int called qnumber so that I can have

LHSquestions[qnumber]

How do I do this? Where would I put something like

private: int qnumber = 0;

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

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"};

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->trackBar1 = (gcnew
System::Windows::Forms::TrackBar());
this->pictureBox1 = (gcnew
System::Windows::Forms::PictureBox());
this->label1 = (gcnew
System::Windows::Forms::Label());
this->label2 = (gcnew
System::Windows::Forms::Label());
this->button1 = (gcnew
System::Windows::Forms::Button());

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


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

this->SuspendLayout();
//
// trackBar1
//
this->trackBar1->Location =
System::Drawing::Point(90, 168);
this->trackBar1->Name = L"trackBar1";
this->trackBar1->Size =
System::Drawing::Size(104, 45);
this->trackBar1->TabIndex = 0;
this->trackBar1->Scroll += gcnew
System::EventHandler(this, &Form1::trackBar1_Scroll);
//
// pictureBox1
//
this->pictureBox1->Image =
(cli::safe_cast<System::Drawing::Image^
(resources->GetObject(L"pictureBox1.Image")));

this->pictureBox1->Location =
System::Drawing::Point(37, 13);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size =
System::Drawing::Size(212, 134);
this->pictureBox1->TabIndex = 1;
this->pictureBox1->TabStop = false;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location =
System::Drawing::Point(27, 182);
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(230, 182);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(31,
13);
this->label2->TabIndex = 3;
this->label2->Text = L"label2";
//
// button1
//
this->button1->Location =
System::Drawing::Point(100, 219);
this->button1->Name = L"button1";
this->button1->Size =
System::Drawing::Size(75, 23);
this->button1->TabIndex = 4;
this->button1->Text = L"NEXT";
this->button1->Click += gcnew
System::EventHandler(this, &Form1::button1_Click);
//
// 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->button1);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->pictureBox1);
this->Controls->Add(this->trackBar1);
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->trackBar1))->EndInit();


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

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

}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e) {
++qnumber;
this->label1->Text = LHSquestions[qnumber];
this->label2->Text = RHSquestions[qnumber];
}
private: System::Void trackBar1_Scroll(System::Object^ sender,
System::EventArgs^ e) {
}

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


One option - You could put all your static array members together.

Also note that you don't need to specify "private" for each declaration.
One
would do.

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

Nov 17 '05 #4
On Wed, 17 Aug 2005 15:06:36 +0530, "Nishant Sivakumar"
<ni**@nospam.asianetindia.com> wrote:
You cannot initialize a non-static member. Either make it static (if it
suites your purpose) or use an initialization list.
Nish,

Sorry - do not follow. I wish to use the qnumber as the index for the
array so I assume it cannot be static? Some how I need to declare and
initialize the int qnumber - but how?

int qnumber = 0;
LHSquestions[qnumber]

Cheers

Geoff

E.g. :-

ref class Test
{
private:
static int count = 10;
int x;
public:
Test():x(10)
{
}
};


Nov 17 '05 #5
Geoff Cox wrote:
Sorry - do not follow. I wish to use the qnumber as the index for the
array so I assume it cannot be static?
Only you know that, it's an important design decision. A static member
variable is shared between all instances of the class. If you declare
your variable static, it means every single object will share the same
variable. A have no idea what qnumber is, and whether it should be
shared or not. Technically a static member is not owned by the object
but the class (all objects ever created within the same .exe or .dll).
Some how I need to declare and initialize the int qnumber - but how?


As Nishant has pointed it out before:

ref class Test
{
private:
int qnumber;
public:
Test();
};

Test::Test
: qnumber(0)
{
//[...]
LHSquestions[qnumber]
//[...]
}

Tom
Nov 17 '05 #6
On Wed, 17 Aug 2005 16:14:53 -0700, Tamas Demjen <td*****@yahoo.com>
wrote:
Only you know that, it's an important design decision. A static member
variable is shared between all instances of the class. If you declare
your variable static, it means every single object will share the same
variable.
Tamas,

Thanks for above - I had misunderstood static ... incidentally I
thought I had found 2 books on Visual C++ 2005 Express but they are
not due out until October/November - can you suggest any good sites
for Visual C++ 2005 Express language for beginners? So far I have
found C# quite a bit easier to understand but I understand that the
combination of Visual C++ 2005 Express and the Windows SDK allows the
creation of Win32 apps .. so that would be interesting. Back to the
error messages ..

I seem to have the correct code for qnumber, the index for the results
array but am getting a couple of errors which you might underatnd!

line 155 error C2227 left of '->ToString' must point to
class/struct/union/generic type
line 181 error C2228 left of '.Close' must have class/struct/union

I have following for initialization which I think is OK.
private: static array<String^>^ LHSquestions = gcnew array<String^>
{"question 1", "question 2"};

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

private: static int qnumber = 0;

private: static array<String^>^ results = gcnew array<String^>
[LHSquestions->Length];

the first error message comes for next line

this->results[qnumber] = trackBar1->Value->ToString(); // line 155

and the second error message for line 188 below

TextWriter^ outfile = gcnew StreamWriter("h:\\a-temp1\\data.txt");

for (int i=0; i < LHSquestions->Length; i++) {
outfile->WriteLine(results[i]);

}

outfile.Close(); // line 188

Cheers

Geoff





A have no idea what qnumber is, and whether it should beshared or not. Technically a static member is not owned by the object
but the class (all objects ever created within the same .exe or .dll).
Some how I need to declare and initialize the int qnumber - but how?


As Nishant has pointed it out before:

ref class Test
{
private:
int qnumber;
public:
Test();
};

Test::Test
: qnumber(0)
{
//[...]
LHSquestions[qnumber]
//[...]
}

Tom


Nov 17 '05 #7
On Wed, 17 Aug 2005 16:14:53 -0700, Tamas Demjen <td*****@yahoo.com>
wrote:

Tam

re my message with the 2 errors - have found the cause of the 2nd one
- I had outfile.Close() instead of outfile->Close()

also found error in the other code but still get 2 similar error
messages

results[qnumber] = trackBar1_Scroll->Value->ToString();

(I had trackBar1 not trackBar1_Scroll)

error messages re above

error C2227: left of '->Value' must point to
class/struct/union/generic type
error C2227: left of '->ToString' must point to
class/struct/union/generic type

thoughts?

Cheers

Geoff
Nov 17 '05 #8
Geoff Cox wrote:
Thanks for above - I had misunderstood static ... incidentally I
thought I had found 2 books on Visual C++ 2005 Express but they are
not due out until October/November - can you suggest any good sites
for Visual C++ 2005 Express language for beginners?
I'm waiting for this book to be published (I don't know when it will be
available):
http://www.amazon.com/exec/obidos/tg...books&n=507846
(or)
http://tinyurl.com/b4c3c

The problem is that your questions are not strictly C++/CLI related.
You're trying to learn C++/CLI without a strong C++ background. I don't
know C++/CLI as extensively as C++ -- few people know it inside out,
other than Microsoft engineers. But knowing C++ well certainly helps a
lot. I'm not saying you'll absolutely have to learn C++ before you can
learn C++/CLI, but given the fact that there are no C++/CLI books
available yet, your best bet at this moment is to rely on existing
resources and the draft standard.
So far I have
found C# quite a bit easier to understand
Difficult problems sometimes can not be addressed efficinetly in a
flexible ways with simple tools. But with .NET you have the advantage of
mixing languages. For example, you may prefer designing the GUI in C#
while writing lower level libraries in C++.
line 155 error C2227 left of '->ToString' must point to
class/struct/union/generic type
line 181 error C2228 left of '.Close' must have class/struct/union


try
..ToString()
->Close()

You use -> for pointers and handles. You use . otherwise (value types,
references). I know it may seem confusing first for people coming from
VC, C#, Delphi and similar languages where . applies to handles as well
as value types. In C++ there is a big difference. In fact, with smart
pointers .get() and ->get() have entirely different meaning, you can't
mix them.

Tom
Nov 17 '05 #9
Tamas Demjen wrote:
I know it may seem confusing first for people coming from
VC, ...


I meant VB not VC.

Tom
Nov 17 '05 #10
On Thu, 18 Aug 2005 10:11:27 -0700, Tamas Demjen <td*****@yahoo.com>
wrote:

Tamas

Thanks for your rhoughts. I have made a couple of steps forward in
that I can now create an array with the same number of elements as
there are in another array!

private: static array<String^>^ results = gcnew
array<String^>(otherArray->Length);

although I do not understand the use of the ^ yet!

Also, have been able to access the Scroll value of the trackbar

trackBar1->Value

Another odd one (to me!) in that the entry to the right of the Scroll
Event in Visual C++ 2005 Express Beta 2 is trackBar1_Scroll so I
thought the value would be

trackBar1_Scroll->Value

One I have not solved yet is making a button invisible - I thought it
would be

button1->Visible(false);

but this does not work! Any ideas?

Cheers

Geoff
I'm waiting for this book to be published (I don't know when it will be
available):
http://www.amazon.com/exec/obidos/tg...books&n=507846
(or)
http://tinyurl.com/b4c3c

The problem is that your questions are not strictly C++/CLI related.
You're trying to learn C++/CLI without a strong C++ background. I don't
know C++/CLI as extensively as C++ -- few people know it inside out,
other than Microsoft engineers. But knowing C++ well certainly helps a
lot. I'm not saying you'll absolutely have to learn C++ before you can
learn C++/CLI, but given the fact that there are no C++/CLI books
available yet, your best bet at this moment is to rely on existing
resources and the draft standard.
So far I have
found C# quite a bit easier to understand


Difficult problems sometimes can not be addressed efficinetly in a
flexible ways with simple tools. But with .NET you have the advantage of
mixing languages. For example, you may prefer designing the GUI in C#
while writing lower level libraries in C++.
line 155 error C2227 left of '->ToString' must point to
class/struct/union/generic type
line 181 error C2228 left of '.Close' must have class/struct/union


try
.ToString()
->Close()

You use -> for pointers and handles. You use . otherwise (value types,
references). I know it may seem confusing first for people coming from
VC, C#, Delphi and similar languages where . applies to handles as well
as value types. In C++ there is a big difference. In fact, with smart
pointers .get() and ->get() have entirely different meaning, you can't
mix them.

Tom


Nov 17 '05 #11
On Thu, 18 Aug 2005 08:49:46 +0100, Geoff Cox <> wrote:

results[qnumber] = trackBar1_Scroll->Value->ToString();


Sorted - it should have been

results[qnumber] = trackBar1->Value.ToString();

Cheers

Geoff
Nov 17 '05 #12

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

Similar topics

9
3373
by: J. Campbell | last post by:
I'm comfortable with arrays from previous programming, and understand the advantages of c++ vectors...I just don't understand how to use them :~( Can you help me to use a vector<string> in the...
15
2023
by: Lasse Skyum | last post by:
I have my own string class that I'm generally verry fond of compared to std::string. For that same reason I'm trying to improve a little on it. Since manny objects in my project will contain...
2
5556
by: Fred Zwarts | last post by:
If I am right, members of a class that are const and not static must be initialized in the initialization part of a constructor. E.g. class C { private: const int I; public: C(); };
15
4837
by: Charles Sullivan | last post by:
Assume I have a static array of structures the elements of which could be any conceivable mixture of C types, pointers, arrays. And this array is uninitialized at program startup. If later in...
3
1964
by: kk_oop | last post by:
Hi. I recently wrote a simple little template that defines an array that checks attempts to use out of bounds indexes. The only problem is that it does provide the use array style value...
5
24302
by: toton | last post by:
Hi, I can initialize an array of class with a specific class as, class Test{ public: Test(int){} }; Test x = {Test(3),Test(6)}; using array initialization list. (Note Test do NOT have a...
7
1891
by: william | last post by:
My question is: Specific memory block where my pointer pointing to changed strangely, seemingly that no statement changed it. Here are two examples I got: ***********1***************** I was...
8
2426
by: Gary | last post by:
When you declare an array of chars and store a string in it, where is the position of the null character \0? And what happens to the unused memory locations? #include <stdio.h> int main(void)...
152
9733
by: vippstar | last post by:
The subject might be misleading. Regardless, is this code valid: #include <stdio.h> void f(double *p, size_t size) { while(size--) printf("%f\n", *p++); } int main(void) { double array = { {...
0
7221
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
7109
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7372
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...
1
7029
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
5619
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,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1537
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.