943,828 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 3177
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Sep 30th, 2008
0

Re: Vector Dimensions

Correct me if I'm wrong, but doesn't the cavet ^ symbol in C++.NET mean that the type is actually a pointer?

c++ Syntax (Toggle Plain Text)
  1. List1.Add(Vec1());
looks fishy... Vec1 is a pointer-type, so doesn't that mean you need to call gcnew to properly instantiate that Vec? O_O

c++ Syntax (Toggle Plain Text)
  1. List1.Add(gcnew Vec1());
I'd assume.
Last edited by Alex Edwards; Sep 30th, 2008 at 12:07 am.
Reputation Points: 392
Solved Threads: 108
Posting Shark
Alex Edwards is offline Offline
971 posts
since Jun 2008
Sep 30th, 2008
0

Re: Vector Dimensions

When using pointers in .NET, you do use * and & to address pointers so the cavet ^ symbol should only meen a type as int and double I beleive like string for the std:: and then String^ for managed.
If I put gcnew before Vec1 in the code below the compiler says this message:

'Vec1' : cannot use this type as argument of 'gcnew'

typedef List<String^>^ Vec1;
typedef List<Vec1> Vec2;

Vec2 List1;

for( int j = 0; j < 1000; j++ )
{	

	List1.Add(gcnew Vec1());

	for( int i = 0; i < 1000; i++ )
	{
		List1[j]->Add("0");
	}

}
Reputation Points: 10
Solved Threads: 1
Posting Pro
Jennifer84 is offline Offline
563 posts
since Feb 2008
Sep 30th, 2008
0

Re: Vector Dimensions

I think you are after ...
C++ Syntax (Toggle Plain Text)
  1. typedef List<String^> Vec1;
  2. typedef List<Vec1^> Vec2;
  3.  
  4. Vec2 List1;
  5.  
  6. for( int j = 0; j < 1000; j++ )
  7. {
  8. List1.Add(gcnew Vec1());
  9.  
  10. for( int i = 0; i < 1000; i++ )
  11. {
  12. List1[j]->Add("0");
  13. }
  14. }
Reputation Points: 1105
Solved Threads: 389
Posting Virtuoso
mitrmkar is offline Offline
1,714 posts
since Nov 2007
Sep 30th, 2008
0

Re: Vector Dimensions

Mitrmkar,

Thank you! Now it works...
Reputation Points: 10
Solved Threads: 1
Posting Pro
Jennifer84 is offline Offline
563 posts
since Feb 2008
Oct 2nd, 2008
0

Re: Vector Dimensions

When compiling the below code I will have a compileerror that says:
String3D : illegal use of this type as an expression
String2D : illegal use of this type as an expression
String1D : illegal use of this type as an expression

I wonder if I doing this correct when trying to iterate through all 3 Dimension with .Count ?


typedef List<String^> String1D;
typedef List<String1D^> String2D;
typedef List<String2D^> String3D;



	String3D Dimensions;	
	int count1 = 0;
	int count2 = -1;


for( int i = 0; i < 5; i++ )
{

	if( i == 0 )
	{
	          Dimensions.Add(gcnew String2D()); 
	}
	if( i >= 0 && i <= 4 )
	{
		count2 = count2 + 1;
		Dimensions[count1]->Add(gcnew String1D()); 
	}
	Dimensions[count1][count2]->Add("TextString");
} 


		
for(int h = 0; h < String3D.Count; ++h)
{
for(int j = 0; j < String2D.Count; ++j)
{
for(int k = 0; k < String1D.Count; ++k)
{
}}}
Last edited by Jennifer84; Oct 2nd, 2008 at 4:01 pm.
Reputation Points: 10
Solved Threads: 1
Posting Pro
Jennifer84 is offline Offline
563 posts
since Feb 2008
Oct 2nd, 2008
0

Re: Vector Dimensions

I found out that "()" was needed. When iterating through the dimensions to show the "TextString" that was put into the List(Dimensions), only 1 MessageBox will appear.
As I have put "TextString" to 5 elements it should be 5 Times.

I am putting the string to these elements:
Dimensions[0][0][0];
Dimensions[0][1][0];
Dimensions[0][2][0];
Dimensions[0][3][0];
Dimensions[0][4][0];


typedef List<String^> String1D;
typedef List<String1D^> String2D;
typedef List<String2D^> String3D;



	String3D Dimensions;	
	int count1 = 0;
	int count2 = -1;


for( int i = 0; i < 5; i++ )
{

	if( i == 0 )
	{
	          Dimensions.Add(gcnew String2D()); 
	}
	if( i >= 0 && i <= 4 )
	{
		count2 = count2 + 1;
		Dimensions[count1]->Add(gcnew String1D()); 
	}
	Dimensions[count1][count2]->Add("TextString");
} 


		
for(int h = 0; h < String3D().Count + 1; ++h)
{
for(int j = 0; j < String2D().Count + 1; ++j)
{
for(int k = 0; k < String1D().Count + 1; ++k)
{

MessageBox::Show(Dimensions[h][j][k]);

}


}}
Last edited by Jennifer84; Oct 2nd, 2008 at 4:31 pm.
Reputation Points: 10
Solved Threads: 1
Posting Pro
Jennifer84 is offline Offline
563 posts
since Feb 2008
Oct 2nd, 2008
0

Re: Vector Dimensions

What I try to find, is the equavilent to the vector ::iterator for the first code.
The first code iterates each Dimension from .begin() to the .end() and then continues
to next dimension for the 3 Dimensions.

C++ Syntax (Toggle Plain Text)
  1. typedef std::vector<string> String1D;
  2. typedef std::vector<String1D> String2D;
  3. typedef std::vector<String2D> String3D;
  4.  
  5. String3D Dimensions;
  6.  
  7. for (String3D::iterator i = Dimensions.begin(); i != Dimensions.end(); ++i)
  8. {
  9. for (String2D::iterator j = i->begin(); j != i->end(); ++j)
  10. {
  11. for (String1D::iterator k = j->begin(); k != j->end(); ++k)
  12. {}}}

As all these Dimensions below for "List" have been ->Add and therefore have different many elements for each Dimension, I am looking for the same(equavilent) method to Iterate each Dimension to the end as the above approach for the std::vector.
Something might be missing in the below code.
C++ Syntax (Toggle Plain Text)
  1. typedef List<String^> String1D;
  2. typedef List<String1D^> String2D;
  3. typedef List<String2D^> String3D;
  4.  
  5. String3D Dimensions;
  6.  
  7. for(int i = 0; i < String3D().Count + 1; ++i)
  8. {
  9. for(int j = 0; j < String2D().Count + 1; ++j)
  10. {
  11. for(int k = 0; k < String1D().Count + 1; ++k)
  12. {}}}
Last edited by Jennifer84; Oct 2nd, 2008 at 7:03 pm.
Reputation Points: 10
Solved Threads: 1
Posting Pro
Jennifer84 is offline Offline
563 posts
since Feb 2008
Oct 3rd, 2008
0

Re: Vector Dimensions

In some way it is needed to refer to the previous vectordimension.
The problem is that I dont know how you refer to the previous dimension beginning and end and set this to some sort of an iterator as this is put ?

String2D::iterator j = i->begin(); j != i->end(); ++j

For the List, I cant find either a begin or end member or iterator.
The below code could be a step closer perheps.
Any idéas or tips would be of help. I am quite stuck.

C++ Syntax (Toggle Plain Text)
  1. for(int i = 0; i < Dimensions.Count; ++i)
  2. {
  3. for(int j = 0; j < String3D().Count; ++j)
  4. {
  5. for(int k = 0; k < String2D().Count; ++k)
  6. {
  7. }}}
Last edited by Jennifer84; Oct 3rd, 2008 at 9:40 am.
Reputation Points: 10
Solved Threads: 1
Posting Pro
Jennifer84 is offline Offline
563 posts
since Feb 2008
Oct 3rd, 2008
0

Re: Vector Dimensions

About this thread starting question: look at my posts in solved threads (two month ago):
http://www.daniweb.com/forums/thread136351.html
http://www.daniweb.com/forums/thread137814.html
Last edited by ArkM; Oct 3rd, 2008 at 12:44 pm.
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Oct 3rd, 2008
0

Re: Vector Dimensions

Yes, this was the thread I was reading on but I missed it and as I saw it was as simple as this. I was imagining me something different.
It helped alot. Great !

C++ Syntax (Toggle Plain Text)
  1. for(int i = 0; i < Dimensions.Count; ++i)
  2. {
  3. for(int j = 0; j < Dimensions[i]->Count; ++j)
  4. {
  5. for(int k = 0; k < Dimensions[i][j]->Count; ++k)
  6. {
  7.  
  8. MessageBox::Show(Dimensions[i][j][k]);
  9.  
  10. }
  11.  
  12.  
  13. }
  14. }

Click to Expand / Collapse  Quote originally posted by ArkM ...
About this thread starting question: look at my posts in solved threads (two month ago):
http://www.daniweb.com/forums/thread136351.html
http://www.daniweb.com/forums/thread137814.html
Last edited by Jennifer84; Oct 3rd, 2008 at 1:44 pm.
Reputation Points: 10
Solved Threads: 1
Posting Pro
Jennifer84 is offline Offline
563 posts
since Feb 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: pls. help in my program
Next Thread in C++ Forum Timeline: Ask about function





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC