C++ question about "syntax structures" 
Author Message
 C++ question about "syntax structures"

Sorry, for my many questions.

Could anybody please tell me how he would translate the code below to
VB6 AndAlso tell me what should be placed in a class and what should be
placed in a module?

Thank you again for the help.
Reiner

#include <iostream>
#include <fstream>
#include <sstream>
#include <map>
#include <string>

using namespace std;

typedef map<string, string> FMap;

struct This_node {
   string MyTag;
   This_node* up;
   This_node* left;
   This_node* right;
   This_node() : MyTag(""), up(NULL), left(NULL), right(NULL) {};

Quote:
};

class MyApp_NodeReader{
  public:

   MyApp_NodeReader(string file);
   This_node* CheckEx(FMap & features) const;
   ~MyApp_NodeReader();

  private:

   This_node* root;
   This_node* LoadTreeFromStream(ifstream & source);
   void DeleteTree(This_node* cur);
   void ShowTree(This_node* cur) const;

Quote:
};



Tue, 14 Feb 2012 03:28:30 GMT  
 C++ question about "syntax structures"
I have some ideas what it could be translated to, but these ideas they
are weird because they would mean recursion in a type definition and I
think that this is not possible. So I must be totally wrong.


Tue, 14 Feb 2012 03:39:47 GMT  
 C++ question about "syntax structures"
Have you tried Googling any of this?  There are *tons* of C to VB examples
out there.  Do a little research man!

--
2025
If you do not believe in time travel,
your beliefs are about to be tempered.

http://www.facebook.com/group.php?gid=43606237254

|I have some ideas what it could be translated to, but these ideas they
| are weird because they would mean recursion in a type definition and I
| think that this is not possible. So I must be totally wrong.



Tue, 14 Feb 2012 04:47:02 GMT  
 C++ question about "syntax structures"
You mean Bing'ing?
Yes, I did, but when you're a newbie all is Greek to you, that's why I
asked for help here.
When I progressed a little more, I will probally laugh at this but right
now I cannot resolve this.

Reiner



Tue, 14 Feb 2012 04:52:10 GMT  
 C++ question about "syntax structures"
A structure in VB cannot contain an instance of itself.  The code cannot be
literally converted to VB.  You could enquire in a C++ group to find out if
that's what this code is trying to do, and whether or not that is legal in
C++.


Quote:
>I have some ideas what it could be translated to, but these ideas they are
>weird because they would mean recursion in a type definition and I think
>that this is not possible. So I must be totally wrong.



Tue, 14 Feb 2012 10:02:38 GMT  
 C++ question about "syntax structures"


Quote:
> I have some ideas what it could be translated to, but these ideas they
> are weird because they would mean recursion in a type definition and I
> think that this is not possible. So I must be totally wrong.

[I'm a bit divided here. Kevin has a point: C++ is OT here, and the best
place to post C++ questions is in a C++ group. But since we started, might
as well finish. In for a penny, in for a pound. lol]

It took me a while to figure out why you thought there was some kind of
"recursion" going on. To me (a C++ programmer) the code looked
straightforward. James' reply supplied the missing ingredient - A C++ struct
and class are the same thing. So what you are thinking of as a VB UDT is
actually a 'class' definition to produce an object in code.

[The details: C++ Structure vs C++ Class
http://learncpp.blogspot.com/2007/05/c-structure-vs-c-class.html ]

struct This_node {
     // the name of the class - "This_node"
   string MyTag;
      // public member - in this case just a string
   This_node* up;
       // public member - reference to another This_node object
   This_node* left;
       // public member - reference to another This_node object
   This_node* right;
       // public member - reference to another This_node object
   This_node() : MyTag(""), up(NULL), left(NULL), right(NULL) {};
       // public constructor - normally not needed as it is the default
       // but used in this context to use what is called an "initializer
list"
       // delimited by the colon
       // this list is used to set the members above to default values
       //   when the object is created

        // minor note in C++ you have to assign a value to a variable
outwise
        // especially for pointers - otherwise it would contain whatever
random values
        // are at that location
        // this is not needed in VB. VB automatically initialized all values
to a
        //   default "empty string" or Null.

Quote:
};

That should be enough to get you started.
Create a VB Class Module with those public members and don't worry about the
last element.

hth
-ralph



Tue, 14 Feb 2012 11:26:41 GMT  
 C++ question about "syntax structures"
Hi Reiner,

Although VB6 complains about it being a circular dependency for UDTs, it
doesn't complain about it when using Classes.  So in VB6 one option you can
use is to use a class instead of a UDT.  This next node pattern is common in
any tree model such as xml.  In VB.NET you can also use Structures as well
as classes, but for VB6 you can only use this pattern with classes.


Quote:
> Sorry, for my many questions.

> Could anybody please tell me how he would translate the code below to VB6
> AndAlso tell me what should be placed in a class and what should be placed
> in a module?

> Thank you again for the help.
> Reiner

> #include <iostream>
> #include <fstream>
> #include <sstream>
> #include <map>
> #include <string>

> using namespace std;

> typedef map<string, string> FMap;

> struct This_node {
>   string MyTag;
>   This_node* up;
>   This_node* left;
>   This_node* right;
>   This_node() : MyTag(""), up(NULL), left(NULL), right(NULL) {};
> };

> class MyApp_NodeReader{
>  public:

>   MyApp_NodeReader(string file);
>   This_node* CheckEx(FMap & features) const;
>   ~MyApp_NodeReader();

>  private:

>   This_node* root;
>   This_node* LoadTreeFromStream(ifstream & source);
>   void DeleteTree(This_node* cur);
>   void ShowTree(This_node* cur) const;
> };



Tue, 14 Feb 2012 11:40:38 GMT  
 C++ question about "syntax structures"


Quote:

<snipped>

> struct This_node {
>      // the name of the class - "This_node"
>    string MyTag;
>       // public member - in this case just a string
>    This_node* up;
>        // public member - reference to another This_node object

Just in case the above would be ...

' in class module "This_node"
         Public MyTag As String
         Public up As This_node
         ...

-ralph



Tue, 14 Feb 2012 11:43:28 GMT  
 C++ question about "syntax structures"


| Hi Reiner,
|
| Although VB6 complains about it being a circular dependency for UDTs, it
| doesn't complain about it when using Classes.  So in VB6 one option you
can
| use is to use a class instead of a UDT.  This next node pattern is common
in
| any tree model such as xml.  In VB.NET you can also use Structures as well
| as classes, but for VB6 you can only use this pattern with classes.

Yeah, no one asked about .Nxt, dirtbag, or aussie.  Same thing.  Stop
trolling my newsgroup with your master's table scraps.  Goon.



Tue, 14 Feb 2012 11:54:57 GMT  
 C++ question about "syntax structures"


|


| > I have some ideas what it could be translated to, but these ideas they
| > are weird because they would mean recursion in a type definition and I
| > think that this is not possible. So I must be totally wrong.
|
| [I'm a bit divided here. Kevin has a point: C++ is OT here, and the best
| place to post C++ questions is in a C++ group. But since we started, might
| as well finish. In for a penny, in for a pound. lol]

It's not so much OT as it is laziness.  If one has a handful of C++ code and
needs help moving it to VB6 code, I would not consider it OT.

That said, what's really been going on as of late with these posts is the OP
asking for a hand out.  He says "Here is the C++ code, how do I make it VB6
code" is three separate posts.  That's my problem.

This group is about support and help, not a "post here and we'll do it for
you" forum.  The OP should post whatever he has tried and then ask what
might be wrong.  Then we step in (or those who know C++ who can step in).
But when you have someone deliberately just tossing C++ code at us and
asking for the conversion, then yes...that's lazy and inappropriate.  We are
here to *help*, not *do*.  And that why I made the comment I made.  Do some
Googling (or Binging, whichever, that's just splitting hairs) and some
reseach of your own.  The OP already admitted to coming directly here for
someone else to tell him how to do it, which goes against what this
community is supposed to be here for:  To help, not to do.

Your a nicer guy than I am Ralph, and I respect you for it.  I stopped
handing out free how to answers a long time ago unless I saw someone post
the code they tried.  Then I would happily fix it for them (minus the "here
is how I would do it in .NxT" drvil McWilly stalks this group with) if I
knew how.

You know the adage:  Fish for a man, he eats for a day, teach him to fish,
he eats for a lifetime.  I do not believe the OP it learning anything since
you and Nobody are doing it for him.  So be it.  I said my piece.

ps - I did Google various C++ to VB6 terms and plenty of information is
available for review.  That is what the OP should have done first.  Then he
might have had something to post which could be fixed.



Tue, 14 Feb 2012 12:05:23 GMT  
 C++ question about "syntax structures"



Quote:


> |


> | > I have some ideas what it could be translated to, but these ideas they
> | > are weird because they would mean recursion in a type definition and I
> | > think that this is not possible. So I must be totally wrong.
> |
> | [I'm a bit divided here. Kevin has a point: C++ is OT here, and the best
> | place to post C++ questions is in a C++ group. But since we started,
might
> | as well finish. In for a penny, in for a pound. lol]

> It's not so much OT as it is laziness.  If one has a handful of C++ code
and
> needs help moving it to VB6 code, I would not consider it OT.

> That said, what's really been going on as of late with these posts is the
OP
> asking for a hand out.  He says "Here is the C++ code, how do I make it
VB6
> code" is three separate posts.  That's my problem.

> This group is about support and help, not a "post here and we'll do it for
> you" forum.  The OP should post whatever he has tried and then ask what
> might be wrong.  Then we step in (or those who know C++ who can step in).
> But when you have someone deliberately just tossing C++ code at us and
> asking for the conversion, then yes...that's lazy and inappropriate.  We
are
> here to *help*, not *do*.  And that why I made the comment I made.  Do
some
> Googling (or Binging, whichever, that's just splitting hairs) and some
> reseach of your own.  The OP already admitted to coming directly here for
> someone else to tell him how to do it, which goes against what this
> community is supposed to be here for:  To help, not to do.

> Your a nicer guy than I am Ralph, and I respect you for it.  I stopped
> handing out free how to answers a long time ago unless I saw someone post
> the code they tried.  Then I would happily fix it for them (minus the
"here
> is how I would do it in .NxT" drvil McWilly stalks this group with) if I
> knew how.

> You know the adage:  Fish for a man, he eats for a day, teach him to fish,
> he eats for a lifetime.  I do not believe the OP it learning anything
since
> you and Nobody are doing it for him.  So be it.  I said my piece.

> ps - I did Google various C++ to VB6 terms and plenty of information is
> available for review.  That is what the OP should have done first.  Then
he
> might have had something to post which could be fixed.

All good points.

You are likely correct on how much we are *really* helping him on the long
run. The OP needs to take some time and learn C++ or enough of it to learn
what to query for.

That's how I learn what little fortran and COBOL I know - from converting
dusty-desk apps, and I don't remember anyone doing it for me, but then I was
too proud back then to even ask. lol

-ralph



Tue, 14 Feb 2012 13:49:30 GMT  
 C++ question about "syntax structures"
Hello Bill,

thanks for the info! That made it clearer to me. And how do I decide
when I should use a class or a UDT?
Can we say that whenever the struct contains a "recursion" I use a
class, otherwise I'll use a UDT. Seems logical to me.

Regards,
Reiner



Tue, 14 Feb 2012 15:18:23 GMT  
 C++ question about "syntax structures"
Thank you Ralph! You really helped me.
That's not something that one can easily figure out himself in a
beginner's state.

Regards,
Reiner



Tue, 14 Feb 2012 15:19:58 GMT  
 C++ question about "syntax structures"


Quote:
> Hello Bill,

> thanks for the info! That made it clearer to me. And how do I decide
> when I should use a class or a UDT?
> Can we say that whenever the struct contains a "recursion" I use a
> class, otherwise I'll use a UDT. Seems logical to me.

VB's Type Statement is used to create a "C-style Struct". The ability to
'package' multiple items into a single variable is a handy feature, but the
real reason VB was given the ability to create UDTs is so it can communicate
with the WinAPI which is a "C" library.

So the 'rule' would be if the c++ program is using the struct as a "C-style
Stuct" then you can convert to a VB UDT. Anything else is a class.

Look up the article "Type Statement" in MSDN help.

VB due to its "interpreted" roots, doesn't allow incomplete or partial
declarations, everything has to be labeled and stored (tokenized) as the
parser comes across each statement. Thus what you are calling 'recursion' is
not allowed in this context. [In other contexts where an item is used before
being declared, VB will create an item for you. However, relying on this
helpful behavior is generally discouraged. <grin>]

-ralph



Tue, 14 Feb 2012 20:18:10 GMT  
 C++ question about "syntax structures"
Hi Reiner,


Quote:
> Hello Bill,

> thanks for the info! That made it clearer to me. And how do I decide when
> I should use a class or a UDT?
> Can we say that whenever the struct contains a "recursion" I use a class,
> otherwise I'll use a UDT. Seems logical to me.

> Regards,
> Reiner

In this case the decision is already made for you ;)  You have to use
classes in VB6 to get the desired functionality.

In other cases, typically UDTs, aka Structures or structs, are used to hold
small bits of data. They have value type qualities which means values are
copied when assigning one struct variable to another.  Classes on the other
hand are reference types, which means variables hold references to the
object in memory.  Assigning one class variable to another means both
variables point to the same object.

Taking the linked list example where each node has a previous node and next
node property, if you were to implement such a thing using structs it would
be very inefficient when it comes to inserting or removing a node as the
assignment to the next and previous node properties would mean copying the
entire list before and after that point. With classes on the other hand it's
a simple change of the reference values to point to the desired object.  So
for a linked list using classes is far more efficient if the list is
changed.
If on the other hand you were using an array as the storage you would have
to move/copy the references or values on an insert or removal anyway, so the
performance would come down to struct size. For small structs, eg a RGBA
color struct, the use of a UDT would be as efficient on the inserts and
deletes, and generally more efficient as it would not require the reference
to point to another object on the heap.

Simple rule of thumb, structs are for small groups of values, classes for
references and behavior. (nb: the "behavior" aspect is a VB6 limitation
where you cannot have properties and methods in UDTs. VB .NET does have
properties and methods in Structures)



Fri, 17 Feb 2012 11:34:50 GMT  
 
 [ 16 post ]  Go to page: [1] [2]

 Relevant Pages 

1. *"*-.,._,.-*"* I"LL TRADE VISUAL C++ FOR VBASIC *"*-.,_,.-*"*

2. "State" Syntax question

3. diffrence between "crystal syntax" and "basic syntax"**

4. File Structure for "Add On" program

5. SOS -- file structure of "dbf" file

6. Newbie syntax question on ":=" and "_"

7. Importing Excel files : "IN" Keyword Syntax

8. "SQL" syntax problem (VB5)

9. ADO "syntax error in FROM clause"

10. "With" syntax

11. syntax for "Full Name" from SAM

12. SQL-syntax and "online-update"

 

 
Powered by phpBB® Forum Software