By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,143 Members | 1,854 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,143 IT Pros & Developers. It's quick & easy.

where to place array initialization?

P: n/a
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
Share this Question
Share on Google+
11 Replies


P: n/a
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

P: n/a
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

P: n/a
> 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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.