Double vector from C++ 
Author Message
 Double vector from C++

   struct t_Struct
   {
     string MyText;
     int MyCount;
   };

   vector <vector <t_Struct> > MyVec;

Can somebody please explain what this double vector declaration would
equal to in VB6?

Thank you.



Sat, 10 Mar 2012 00:20:48 GMT  
 Double vector from C++

Quote:

>    struct t_Struct
>    {
>      string MyText;
>      int MyCount;
>    };

>    vector <vector <t_Struct> > MyVec;

> Can somebody please explain what this double vector declaration
> would equal to in VB6?

Presumably, it would be an array containing arrays of t_Struct. You
probably can't get exactly this from VB.

--
   Jim Mack
   Twisted tees at http://www.cafepress.com/2050inc
   "We sew confusion"



Sat, 10 Mar 2012 00:28:44 GMT  
 Double vector from C++

Quote:
>   struct t_Struct
>   {
>     string MyText;
>     int MyCount;
>   };

>   vector <vector <t_Struct> > MyVec;

> Can somebody please explain what this double vector declaration would
> equal to in VB6?

http://en.wikipedia.org/wiki/Vector_(C%2B%2B)

http://www.learncpp.com/

http://www.cplusplus.com/



Sat, 10 Mar 2012 00:28:36 GMT  
 Double vector from C++

Quote:

>    struct t_Struct
>    {
>      string MyText;
>      int MyCount;
>    };

>    vector <vector <t_Struct> > MyVec;

> Can somebody please explain what this double vector declaration would
> equal to in VB6?

> Thank you.

As noted it would be an array or arrays of t_struct.

If you wanted to mimic this object in VB you could go either of two routes
(or a hybrid of both). By 'mimic' I mean create an object that would respond
to messaging similar to a C++ vector of vectors ...
1) Create a collection wrapper that can manage a "t_Struct" class. The
wrapper would hold a master collection that managed additional collections.
Management would be similar to how one piddles with RecordSets
2) Create your wrapper that managed internal arrays of a t_struct UDT.

-ralph



Sat, 10 Mar 2012 01:41:52 GMT  
 Double vector from C++

Dear Ralph,

is it possible to show me a quick example?
I really do not understand the

vector <vector <...

thing. I don't see why we use vector 2 times.
In my eyes t_Struct would equal to

private type t_Struct
        MyText as string
        MyCount as long
end type

private MyVec() as t_Struct

It is completely unclear to me what <vector <vector would equal to.

Regards,
Hermann

Ralph schrieb:

Quote:

>>    struct t_Struct
>>    {
>>      string MyText;
>>      int MyCount;
>>    };

>>    vector <vector <t_Struct> > MyVec;

>> Can somebody please explain what this double vector declaration would
>> equal to in VB6?

>> Thank you.

> As noted it would be an array or arrays of t_struct.

> If you wanted to mimic this object in VB you could go either of two routes
> (or a hybrid of both). By 'mimic' I mean create an object that would respond
> to messaging similar to a C++ vector of vectors ...
> 1) Create a collection wrapper that can manage a "t_Struct" class. The
> wrapper would hold a master collection that managed additional collections.
> Management would be similar to how one piddles with RecordSets
> 2) Create your wrapper that managed internal arrays of a t_struct UDT.

> -ralph



Sat, 10 Mar 2012 03:19:39 GMT  
 Double vector from C++

Quote:

> It is completely unclear to me what <vector <vector would equal to.

See if this helps:

http://www.youtube.com/watch?v=mNRXJEE3Nz8



Sat, 10 Mar 2012 03:45:47 GMT  
 Double vector from C++


Quote:
> Dear Ralph,

> is it possible to show me a quick example?
> I really do not understand the

> vector <vector <...

It's like a dynamic two dimensional array.  Read it like:

vector of vector of t_struct.

In other words, you are creating a vector that can only hold vectors that can
only hold t_struct.  a vector of vector of t_struct :)

--
Tom Shelton



Sat, 10 Mar 2012 05:01:41 GMT  
 Double vector from C++

Quote:

> Dear Ralph,

> is it possible to show me a quick example?
> I really do not understand the

> vector <vector <...

> thing. I don't see why we use vector 2 times.
> In my eyes t_Struct would equal to

> private type t_Struct
> MyText as string
> MyCount as long
> end type

> private MyVec() as t_Struct

> It is completely unclear to me what <vector <vector would equal to.

> Regards,
> Hermann

The vector<type> construct is simply a C++ mechanism for creating a 'vector'
class from a template (this one from the STL). So if I do this ...
     vector<type> MyVec
The compiler (pre-processor actually) will create an "array" class (object
at runtime)  that contains "types" as elements. This would translate to
something like what you posted ...
      Private MyVecSub() As t_Struct  ' let's call it a sub-vector for now
The outer 'vector' construct simply means we will have another vector that
contains vectors as elements, and each of these vectors will be "arrays" of
vectors of type t_Struct. So this would convert to something like this ...
       Private MyVecSub() As t_Struct
       Private MyVec() As MyVecSub()   ' not legal in VB
An 'array' where each element is an 'array' of t_Structs.

Here is just one example of how you might do it (an ugly one at that. lol)

' Class Module Nameed CT_Struct
' using the struct as an object
Option Explicit

Public MyArray As String  ' added for illustration to show the array
Public MyText As String    ' your element
Public MyCount As Long    ' your element

In a form
' Form1
Option Explicit

    ' hardcoded sizes - but you could redim, etc.
Private MyVec(2) As  Variant
Dim St As                   CT_Struct
Dim aSt(3) As             CT_Struct

Private Sub Command1_Click()
    Dim i As Long
    Dim j As Long
        ' create a couple of Arrays containing CStructs
    For j = 0 To 2
        For i = 0 To 3
            Set St = New CT_Struct
            St.MyArray = CStr(j)
            St.MyText = "String" & CStr(i)
            St.MyCount = i
            Set aSt(i) = St
            Set St = Nothing
        Next i
                ' add an array of structs
        MyVec(j) = aSt
    Next j
        ' print it out for display
    Dim jnk, ar   ' variants
    For Each jnk In MyVec
        For Each ar In jnk
            Debug.Print ar.MyArray
            Debug.Print ar.MyText
            Debug.Print ar.MyCount
        Next
    Next

End Sub

-ralph



Sat, 10 Mar 2012 04:55:13 GMT  
 Double vector from C++

Quote:


>> Dear Ralph,

>> is it possible to show me a quick example?

I vaguely remember McKinney doing something on this ... sure enough there is
an example in the MSDN.
Open the library and do a Search for "CVector Implementation" for another
example.

-ralph



Sat, 10 Mar 2012 05:12:14 GMT  
 Double vector from C++


Quote:
> It is completely unclear to me what <vector <vector would equal to.

And array whose menbers are arrays.  In your case each member of
the inner arrays are defined types.  Here an example where each
member of the inner array are simple strings:

  vec = Array(Array("one", "two", "three"), _
              Array("uno", "dos", "tres"), _
              Array("eins", "drei", "zwei"))

  Debug.Print vec(0)(0)  ' one
  Debug.Print vec(1)(1)  ' dos
  Debug.Print vec(2)(2)  ' zwei

Now suppose you add a class that contains the members:

' Class1 code
Public MyText As String
Public MyCount As Long

And you create a routine that creates a new object from that class:

Function NC(Text As String) As Class1
  Set NC = New Class1
  NC.MyText = Text
End Function

Now you can use that in place of the inner member's strings:

  vec = Array(Array(NC("one"), NC("two"), NC("three")), _
              Array(NC("uno"), NC("dos"), NC("tres")), _
              Array(NC("eins"), NC("drei"), NC("zwei")))

  Debug.Print vec(2)(0).MyText  ' eins
  Debug.Print vec(1)(1).MyText  ' dos
  Debug.Print vec(0)(2).MyText  ' three

So there you have each member of the 'vec' array is itself
an array whose members are specific object types.

LFS



Sat, 10 Mar 2012 05:33:36 GMT  
 Double vector from C++

Hello Ralph,

thank you!
That helped me a lot!

Regards,
Hermann

Ralph schrieb:

Quote:

>> Dear Ralph,

>> is it possible to show me a quick example?
>> I really do not understand the

>> vector <vector <...

>> thing. I don't see why we use vector 2 times.
>> In my eyes t_Struct would equal to

>> private type t_Struct
>> MyText as string
>> MyCount as long
>> end type

>> private MyVec() as t_Struct

>> It is completely unclear to me what <vector <vector would equal to.

>> Regards,
>> Hermann

> The vector<type> construct is simply a C++ mechanism for creating a 'vector'
> class from a template (this one from the STL). So if I do this ...
>      vector<type> MyVec
> The compiler (pre-processor actually) will create an "array" class (object
> at runtime)  that contains "types" as elements. This would translate to
> something like what you posted ...
>       Private MyVecSub() As t_Struct  ' let's call it a sub-vector for now
> The outer 'vector' construct simply means we will have another vector that
> contains vectors as elements, and each of these vectors will be "arrays" of
> vectors of type t_Struct. So this would convert to something like this ...
>        Private MyVecSub() As t_Struct
>        Private MyVec() As MyVecSub()   ' not legal in VB
> An 'array' where each element is an 'array' of t_Structs.

> Here is just one example of how you might do it (an ugly one at that. lol)

> ' Class Module Nameed CT_Struct
> ' using the struct as an object
> Option Explicit

> Public MyArray As String  ' added for illustration to show the array
> Public MyText As String    ' your element
> Public MyCount As Long    ' your element

> In a form
> ' Form1
> Option Explicit

>     ' hardcoded sizes - but you could redim, etc.
> Private MyVec(2) As  Variant
> Dim St As                   CT_Struct
> Dim aSt(3) As             CT_Struct

> Private Sub Command1_Click()
>     Dim i As Long
>     Dim j As Long
>         ' create a couple of Arrays containing CStructs
>     For j = 0 To 2
>         For i = 0 To 3
>             Set St = New CT_Struct
>             St.MyArray = CStr(j)
>             St.MyText = "String" & CStr(i)
>             St.MyCount = i
>             Set aSt(i) = St
>             Set St = Nothing
>         Next i
>                 ' add an array of structs
>         MyVec(j) = aSt
>     Next j
>         ' print it out for display
>     Dim jnk, ar   ' variants
>     For Each jnk In MyVec
>         For Each ar In jnk
>             Debug.Print ar.MyArray
>             Debug.Print ar.MyText
>             Debug.Print ar.MyCount
>         Next
>     Next

> End Sub

> -ralph



Sat, 10 Mar 2012 05:33:58 GMT  
 Double vector from C++

Dear Ralph,

when I create a class called t_Struct like this:
--------------------------------
Option Explicit

Private m_sText() As Long
Private m_lCount() As Long
Private m_lItems As Long

Private Sub Class_Initialize()

     ReDim m_sText(0)
     ReDim m_lCount(0)
     m_lItems = 0

End Sub
Public Sub AddItem(ByVal uText As String, ByVal uCount As Long)

     m_lItems = m_lItems + 1

     ReDim Preserve m_sText(0 To m_sText)
     ReDim Preserve m_lCount(0 To m_lItems)

     m_sText(m_lItems) = uText
     m_lCount(m_lItems) = uCount

End Sub

Public Property Get Text(ByVal uIndex As Long) As String

     Text = m_sText(uIndex)

End Property

Public Property Get Count(ByVal uIndex As Long) As Long

     Count = m_lCount(uIndex)

End Property
-------------------------------------------
... I could smoothly iterate it.

I would declare it as

Private m_t_Struct() as t_Struct (e. g. on a form)

I would then have an array of an array, right?

Is that what you would call a wrapper?

Regards,
Hermann

Ralph schrieb:

Quote:

>> Dear Ralph,

>> is it possible to show me a quick example?
>> I really do not understand the

>> vector <vector <...

>> thing. I don't see why we use vector 2 times.
>> In my eyes t_Struct would equal to

>> private type t_Struct
>> MyText as string
>> MyCount as long
>> end type

>> private MyVec() as t_Struct

>> It is completely unclear to me what <vector <vector would equal to.

>> Regards,
>> Hermann

> The vector<type> construct is simply a C++ mechanism for creating a 'vector'
> class from a template (this one from the STL). So if I do this ...
>      vector<type> MyVec
> The compiler (pre-processor actually) will create an "array" class (object
> at runtime)  that contains "types" as elements. This would translate to
> something like what you posted ...
>       Private MyVecSub() As t_Struct  ' let's call it a sub-vector for now
> The outer 'vector' construct simply means we will have another vector that
> contains vectors as elements, and each of these vectors will be "arrays" of
> vectors of type t_Struct. So this would convert to something like this ...
>        Private MyVecSub() As t_Struct
>        Private MyVec() As MyVecSub()   ' not legal in VB
> An 'array' where each element is an 'array' of t_Structs.

> Here is just one example of how you might do it (an ugly one at that. lol)

> ' Class Module Nameed CT_Struct
> ' using the struct as an object
> Option Explicit

> Public MyArray As String  ' added for illustration to show the array
> Public MyText As String    ' your element
> Public MyCount As Long    ' your element

> In a form
> ' Form1
> Option Explicit

>     ' hardcoded sizes - but you could redim, etc.
> Private MyVec(2) As  Variant
> Dim St As                   CT_Struct
> Dim aSt(3) As             CT_Struct

> Private Sub Command1_Click()
>     Dim i As Long
>     Dim j As Long
>         ' create a couple of Arrays containing CStructs
>     For j = 0 To 2
>         For i = 0 To 3
>             Set St = New CT_Struct
>             St.MyArray = CStr(j)
>             St.MyText = "String" & CStr(i)
>             St.MyCount = i
>             Set aSt(i) = St
>             Set St = Nothing
>         Next i
>                 ' add an array of structs
>         MyVec(j) = aSt
>     Next j
>         ' print it out for display
>     Dim jnk, ar   ' variants
>     For Each jnk In MyVec
>         For Each ar In jnk
>             Debug.Print ar.MyArray
>             Debug.Print ar.MyText
>             Debug.Print ar.MyCount
>         Next
>     Next

> End Sub

> -ralph



Sat, 10 Mar 2012 05:46:44 GMT  
 Double vector from C++
Wow, another way to Rome!

Thank you!

Hermann

Larry Serflaten schrieb:

Quote:

>> It is completely unclear to me what <vector <vector would equal to.

> And array whose menbers are arrays.  In your case each member of
> the inner arrays are defined types.  Here an example where each
> member of the inner array are simple strings:

>   vec = Array(Array("one", "two", "three"), _
>               Array("uno", "dos", "tres"), _
>               Array("eins", "drei", "zwei"))

>   Debug.Print vec(0)(0)  ' one
>   Debug.Print vec(1)(1)  ' dos
>   Debug.Print vec(2)(2)  ' zwei

> Now suppose you add a class that contains the members:

> ' Class1 code
> Public MyText As String
> Public MyCount As Long

> And you create a routine that creates a new object from that class:

> Function NC(Text As String) As Class1
>   Set NC = New Class1
>   NC.MyText = Text
> End Function

> Now you can use that in place of the inner member's strings:

>   vec = Array(Array(NC("one"), NC("two"), NC("three")), _
>               Array(NC("uno"), NC("dos"), NC("tres")), _
>               Array(NC("eins"), NC("drei"), NC("zwei")))

>   Debug.Print vec(2)(0).MyText  ' eins
>   Debug.Print vec(1)(1).MyText  ' dos
>   Debug.Print vec(0)(2).MyText  ' three

> So there you have each member of the 'vec' array is itself
> an array whose members are specific object types.

> LFS



Sat, 10 Mar 2012 05:48:26 GMT  
 Double vector from C++
Instead of having a vector of vectors why not just to use a matrix?

Private mMatrix(MaxX , MaxY) as t_Struct



Sat, 10 Mar 2012 08:47:49 GMT  
 Double vector from C++


Quote:
> Wow, another way to Rome!

> Thank you!

Please be aware that was to help clarify the issue, it
is not the most efficient means to do the task.  As I
see it, Eduardo's multi-dimensional array would be
better, if that will fit the need....

Good luck!
LFS



Sat, 10 Mar 2012 19:49:33 GMT  
 
 [ 15 post ] 

 Relevant Pages 

1. C++ Vector class for VB

2. Using Double variable with a C++ dll

3. converting string containing binary double to double

4. QBasic MBF Double Conversion to VB6 Floating Point Double

5. VB call C++: how to handle C++ exceptions

6. Question: Is Visual C++ a real C++ builder?

7. Calling a C++ DLL function which takes an C++ object as parameter

8. Visual C++ & Visual Age c++

9. Visual C++ vs Borland C++ advice

10. accessing objects in a c++ DLL from a c++ activeX control placed in a VB application

11. Mathematical: Does a vector cross an area

12. Putting Vector Graphics Into The Clipboard

 

 
Powered by phpBB® Forum Software