Vector Dimensions

Thread Solved

Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 108
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

Re: Vector Dimensions

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

  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

  1. List1.Add(gcnew Vec1());
I'd assume.
Last edited by Alex Edwards; Sep 29th, 2008 at 11:07 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 518
Reputation: Jennifer84 is an unknown quantity at this point 
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro

Re: Vector Dimensions

 
0
  #12
Sep 30th, 2008
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");
	}

}
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 1,294
Reputation: mitrmkar is a splendid one to behold mitrmkar is a splendid one to behold mitrmkar is a splendid one to behold mitrmkar is a splendid one to behold mitrmkar is a splendid one to behold mitrmkar is a splendid one to behold 
Solved Threads: 267
mitrmkar mitrmkar is offline Offline
Nearly a Posting Virtuoso

Re: Vector Dimensions

 
0
  #13
Sep 30th, 2008
I think you are after ...
  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. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 518
Reputation: Jennifer84 is an unknown quantity at this point 
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro

Re: Vector Dimensions

 
0
  #14
Sep 30th, 2008
Mitrmkar,

Thank you! Now it works...
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 518
Reputation: Jennifer84 is an unknown quantity at this point 
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro

Re: Vector Dimensions

 
0
  #15
Oct 2nd, 2008
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 3:01 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 518
Reputation: Jennifer84 is an unknown quantity at this point 
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro

Re: Vector Dimensions

 
0
  #16
Oct 2nd, 2008
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 3:31 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 518
Reputation: Jennifer84 is an unknown quantity at this point 
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro

Re: Vector Dimensions

 
0
  #17
Oct 2nd, 2008
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.

  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.
  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 6:03 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 518
Reputation: Jennifer84 is an unknown quantity at this point 
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro

Re: Vector Dimensions

 
0
  #18
Oct 3rd, 2008
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.

  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 8:40 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 344
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Vector Dimensions

 
0
  #19
Oct 3rd, 2008
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 11:44 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 518
Reputation: Jennifer84 is an unknown quantity at this point 
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro

Re: Vector Dimensions

 
0
  #20
Oct 3rd, 2008
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 !

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

Originally Posted by ArkM View Post
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 12:44 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 2408 | Replies: 19
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC