| | |
Vector Dimensions
Thread Solved |
Correct me if I'm wrong, but doesn't the cavet ^ symbol in C++.NET mean that the type is actually a pointer?
looks fishy... Vec1 is a pointer-type, so doesn't that mean you need to call gcnew to properly instantiate that Vec? O_O
I'd assume.
c++ Syntax (Toggle Plain Text)
List1.Add(Vec1());
c++ Syntax (Toggle Plain Text)
List1.Add(gcnew Vec1());
Last edited by Alex Edwards; Sep 29th, 2008 at 11:07 pm.
•
•
Join Date: Feb 2008
Posts: 518
Reputation:
Solved Threads: 1
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'
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");
}
}•
•
Join Date: Nov 2007
Posts: 1,294
Reputation:
Solved Threads: 267
I think you are after ...
C++ Syntax (Toggle Plain Text)
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"); } }
•
•
Join Date: Feb 2008
Posts: 518
Reputation:
Solved Threads: 1
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 ?
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.
•
•
Join Date: Feb 2008
Posts: 518
Reputation:
Solved Threads: 1
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];
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.
•
•
Join Date: Feb 2008
Posts: 518
Reputation:
Solved Threads: 1
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.
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.
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)
typedef std::vector<string> String1D; typedef std::vector<String1D> String2D; typedef std::vector<String2D> String3D; String3D Dimensions; for (String3D::iterator i = Dimensions.begin(); i != Dimensions.end(); ++i) { for (String2D::iterator j = i->begin(); j != i->end(); ++j) { for (String1D::iterator k = j->begin(); k != j->end(); ++k) {}}}
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)
typedef List<String^> String1D; typedef List<String1D^> String2D; typedef List<String2D^> String3D; String3D Dimensions; for(int i = 0; i < String3D().Count + 1; ++i) { for(int j = 0; j < String2D().Count + 1; ++j) { for(int k = 0; k < String1D().Count + 1; ++k) {}}}
Last edited by Jennifer84; Oct 2nd, 2008 at 6:03 pm.
•
•
Join Date: Feb 2008
Posts: 518
Reputation:
Solved Threads: 1
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.
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)
for(int i = 0; i < Dimensions.Count; ++i) { for(int j = 0; j < String3D().Count; ++j) { for(int k = 0; k < String2D().Count; ++k) { }}}
Last edited by Jennifer84; Oct 3rd, 2008 at 8:40 am.
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
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.
•
•
Join Date: Feb 2008
Posts: 518
Reputation:
Solved Threads: 1
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 !
It helped alot. Great !
C++ Syntax (Toggle Plain Text)
for(int i = 0; i < Dimensions.Count; ++i) { for(int j = 0; j < Dimensions[i]->Count; ++j) { for(int k = 0; k < Dimensions[i][j]->Count; ++k) { MessageBox::Show(Dimensions[i][j][k]); } } }
•
•
•
•
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.
![]() |
Similar Threads
- Finding any tangent vector (3D) (Game Development)
- list inside vector (Java)
- Vector of vectors & magic square issues (C++)
- What relation does **indirection operator have with Multidimensional Arrays (C++)
- 2D Vector (C++)
- Made my own vector thingy (C)
- Need help starting program using vector (C++)
- SIMPLE BOX GIVING ME PROBLEMS--this is homeowrk but i have tried for hours (Java)
Other Threads in the C++ Forum
- Previous Thread: pls. help in my program
- Next Thread: Ask about function
Views: 2408 | Replies: 19
| Thread Tools | Search this Thread |
Tag cloud for C++
algorithm array arrays assignment beginner binary c++ c/c++ calculator char class classes client code command compile compiler console constructor conversion convert count delete dll dynamic encryption error exception file files fstream function functions game givemetehcodez graph gui helpwithhomework homework http iamthwee ifstream input int lazy linker list loop looping loops math matrix member memory multidimensional newbie number object objects opengl output parameter pointer pointers problem program programming project qt random read recursion recursive reference simple sockets sort spoonfeeding string strings struct student studio system template templates text time tree url variable vc++ vector video visual win32 window windows winsock xml






