473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Learning about Nodes:

I have been using C++ for several years now and I have been reading
about nodes. I am a little confused. I understand many of the
concepts behind this such as pointers and dynamic binding. My main
problem is that I have yet to have a use for them in any of the
projects. that I write. I wrote this from what I read about nodes.
This is very simple program or object I wrote from what I read:

public:
color() : rc(0), rg(0), rb(0) {}
color(int r, int g, int b) : rc(r), rg(g), rb(b) {}
color(color, color);
int r()const {return rc;}
int g()const {return rg;}
int b()const {return rb;}
};

#endif

color::color(color c1, color c2){
rc = c1.r()+c2.r()/2;
rg = c1.g()+c2.g()/2;
rb = c1.b()+c2.b()/2;
}

I realize that that nodes use handles and dynamic binding. What is a
simple program that I can write to learn how to do this and for it to
be useful. I am pretty weak on handles, again that is somthing I don't
use much because the std::libraries are so useful.

Aug 29 '06 #1
11 1677

"JoeC" <en*****@yahoo.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
>I have been using C++ for several years now and I have been reading
about nodes. I am a little confused. I understand many of the
concepts behind this such as pointers and dynamic binding. My main
problem is that I have yet to have a use for them in any of the
projects. that I write.
And you most likely won't. From my understanding, nodes are used primarily
for linked lists. Unless you are using some different term for nodes,
because the code you show has nothing to do with nodes as I know them.
I wrote this from what I read about nodes.
This is very simple program or object I wrote from what I read:

public:
color() : rc(0), rg(0), rb(0) {}
color(int r, int g, int b) : rc(r), rg(g), rb(b) {}
color(color, color);
int r()const {return rc;}
int g()const {return rg;}
int b()const {return rb;}
};

#endif

color::color(color c1, color c2){
rc = c1.r()+c2.r()/2;
rg = c1.g()+c2.g()/2;
rb = c1.b()+c2.b()/2;
}

I realize that that nodes use handles and dynamic binding. What is a
simple program that I can write to learn how to do this and for it to
be useful. I am pretty weak on handles, again that is somthing I don't
use much because the std::libraries are so useful.

Aug 29 '06 #2
JoeC wrote:
I have been using C++ for several years now and I have been reading
about nodes. I am a little confused.
Me too. I've been using C++ for well over ten years, and I have no
idea what a C++ node is.
I understand many of the
concepts behind this such as pointers and dynamic binding. My main
problem is that I have yet to have a use for them in any of the
projects. that I write. I wrote this from what I read about nodes.
Again, what on earth is a node?
This is very simple program or object I wrote from what I read:

public:
color() : rc(0), rg(0), rb(0) {}
color(int r, int g, int b) : rc(r), rg(g), rb(b) {}
color(color, color);
int r()const {return rc;}
int g()const {return rg;}
int b()const {return rb;}
};

#endif

color::color(color c1, color c2){
rc = c1.r()+c2.r()/2;
rg = c1.g()+c2.g()/2;
rb = c1.b()+c2.b()/2;
}
You see seem to have made a mistake and only cut and pasted part of the
code. Where is the beginning of the class definition? And what does
this have to do with nodes?
I realize that that nodes use handles and dynamic binding.
What is a handle?
What is a
simple program that I can write to learn how to do this and for it to
be useful. I am pretty weak on handles, again that is somthing I don't
use much because the std::libraries are so useful.
What are the "std::libraries"? Do you mean the C++ standard library?
I don't think the C++ standard library has either "nodes" or "handles."

Is it possible you're talking about a different language, or something
that is implementation-specific?

Best regards,

Tom

Aug 29 '06 #3

JoeC wrote:
I have been using C++ for several years now and I have been reading
about nodes. I am a little confused. I understand many of the
concepts behind this such as pointers and dynamic binding. My main
problem is that I have yet to have a use for them in any of the
projects. that I write. I wrote this from what I read about nodes.
This is very simple program or object I wrote from what I read:

public:
color() : rc(0), rg(0), rb(0) {}
color(int r, int g, int b) : rc(r), rg(g), rb(b) {}
color(color, color);
int r()const {return rc;}
int g()const {return rg;}
int b()const {return rb;}
};

#endif

color::color(color c1, color c2){
rc = c1.r()+c2.r()/2;
rg = c1.g()+c2.g()/2;
rb = c1.b()+c2.b()/2;
}

I realize that that nodes use handles and dynamic binding. What is a
simple program that I can write to learn how to do this and for it to
be useful. I am pretty weak on handles, again that is somthing I don't
use much because the std::libraries are so useful.
I worte a stimple linked list. I had couldn't realy make it a
template. I was readind the books by Koening and Moo and they went
into handles and from that they went into creating a program that used
nodes. I would like to try to build a program that uses nodes. I
realize nodes use dynamic binding. I wrote simple program that used
binding but like from my color program you can take two objects and
create new objects. They used an example how the compiler does math
statments.

(5*2) + (5*2), I just got confused because they were using things
derived from iostream.

Aug 30 '06 #4
What is a handle?
Handles are often known as smart poiters. They make dynamic binding
much easier by handling the memory allocation inside an object and the
user doesn't have to worry about all that.
>
What is a
simple program that I can write to learn how to do this and for it to
be useful. I am pretty weak on handles, again that is somthing I don't
use much because the std::libraries are so useful.

What are the "std::libraries"? Do you mean the C++ standard library?
I don't think the C++ standard library has either "nodes" or "handles."
They don't they are design paterns and algorithms. These are things
that have to be learned and implemented in the language.
Is it possible you're talking about a different language, or something
that is implementation-specific?
No, I would suggest that you do some research in intermedate to
advanced programming. Look at my color program, it can be created with
data to create an object or it can be created with other colors. In a
way that is a node. A color can create other color when they are
mixed. In a way each color is a node but it is much simpler that the
examples that inspired this program. This is as far as I understand.
Basically a node is is used for repeating paterns. It is pretty
complecated and you have to know how to create a handle. I am not even
sure what it is called in objects that create nodes. I am always
trying to expand my knowlege of C++ and embark on new challenges.

Best regards,

Tom
Aug 30 '06 #5
In article <11**********************@i3g2000cwc.googlegroups. com>,
"JoeC" <en*****@yahoo.comwrote:
I realize that that nodes use handles and dynamic binding. What is a
simple program that I can write to learn how to do this and for it to
be useful. I am pretty weak on handles, again that is somthing I don't
use much because the std::libraries are so useful.
Joe,

Your asking a hard one. A program that uses polymorphism (dynamic
binding) out of need is almost necessarily quite large. I thought about
this quite a bit and came up with an idea but I don't know for sure if
polymorphism would be the best solution... Write a program that can
score both 10-pin and 5-pin bowling games.
Aug 30 '06 #6

Daniel T. wrote:
In article <11**********************@i3g2000cwc.googlegroups. com>,
"JoeC" <en*****@yahoo.comwrote:
I realize that that nodes use handles and dynamic binding. What is a
simple program that I can write to learn how to do this and for it to
be useful. I am pretty weak on handles, again that is somthing I don't
use much because the std::libraries are so useful.

Joe,

Your asking a hard one. A program that uses polymorphism (dynamic
binding) out of need is almost necessarily quite large. I thought about
this quite a bit and came up with an idea but I don't know for sure if
polymorphism would be the best solution... Write a program that can
score both 10-pin and 5-pin bowling games.
That is what I get for asking the question, but I see your point. Can
I use the code I have already used? I know it is not perfect but it
works. Not exactly what I had in mind but it will work for the case of
dynamic binding then that leads into handles. I will do the work on
the program when I have the time. I will send it to you for your
opinion for now I will send a simple program I did that uses dynamic
binding.

I was reading on the topic and the best I could do is my color program.
I guess there is a great deal that goes into the proscess and there
are steps to getting there. Lately I have been working on my map game.
It works realy good I have just having trouble with the combat system.
I want to take all the units in the same space and add up the attack
and defense factors to create odds and combat table. I have gotten to
a point and I am at a loss why I my function does not work.

I finished my response a while ago but my cable modem won't stay
connected so I keep writing waiting for it to connect.

Aug 30 '06 #7
"JoeC" <en*****@yahoo.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com
I have been using C++ for several years now and I have been reading
about nodes. I am a little confused. I understand many of the
concepts behind this such as pointers and dynamic binding. My main
problem is that I have yet to have a use for them in any of the
projects. that I write. I wrote this from what I read about nodes.
This is very simple program or object I wrote from what I read:

public:
color() : rc(0), rg(0), rb(0) {}
color(int r, int g, int b) : rc(r), rg(g), rb(b) {}
color(color, color);
int r()const {return rc;}
int g()const {return rg;}
int b()const {return rb;}
};

#endif

color::color(color c1, color c2){
rc = c1.r()+c2.r()/2;
rg = c1.g()+c2.g()/2;
rb = c1.b()+c2.b()/2;
}

I realize that that nodes use handles and dynamic binding. What is a
simple program that I can write to learn how to do this and for it to
be useful. I am pretty weak on handles, again that is somthing I
don't use much because the std::libraries are so useful.
On my understanding, a node is an object that is meant to be linked to other
objects of the same type using pointers that are data members of the object.
The two main examples are objects in a linked list and in a tree.

The list class in the standard library uses a linked list and the set and
map classes use a tree (the C++ standard doesn't explicitly require this,
but in practice that is how they are implemented). Any objects that you
store in those containers are embedded inside a node that contains the
necessary pointers to other nodes.

Any text on data structures will have code showing lists and trees. Or see
here:

http://en.wikipedia.org/wiki/Linked_list

http://en.wikipedia.org/wiki/Binary_tree

--
John Carson
Aug 30 '06 #8
LR
JoeC wrote:
>>What is a handle?


Handles are often known as smart poiters.
I'm not sure that's correct. A quick look at foldoc seems to contradict
this.
http://foldoc.org/foldoc.cgi?query=handle&action=Search
>
They make dynamic binding
much easier by handling the memory allocation inside an object and the
user doesn't have to worry about all that.
I don't think that smart pointers are directly related to dynamic
binding in the way you suggest.

Please see http://foldoc.org/?query=dynamic+binding


>>Is it possible you're talking about a different language, or something
that is implementation-specific?
I'm curious about this too. For example, Handles are used quite a bit
in Windows programming.

No, I would suggest that you do some research in intermedate to
advanced programming. Look at my color program, it can be created with
data to create an object or it can be created with other colors. In a
way that is a node.
In what way? I've heard several definitions for node, but the one
you've given doesn't compute for me.
http://foldoc.org/foldoc.cgi?query=node&action=Search

A color can create other color when they are
mixed. In a way each color is a node but it is much simpler that the
examples that inspired this program. This is as far as I understand.
Basically a node is is used for repeating paterns. It is pretty
complecated and you have to know how to create a handle. I am not even
sure what it is called in objects that create nodes.
I'm sorry, but I can't understand what the above means.

How is each color a node?

What are objects that create nodes?

I am always
trying to expand my knowlege of C++ and embark on new challenges.
May I ask why you passed the Colors by value to your ctor in an earlier
post in this thread? I think it was something like

Color(Color a, Color b) {
rc = c1.r() + c2.r()/2;
...
}

Which btw, won't do what I think you might want it to do. I could be
mistaken about that.

How about making a global:

int average(const int a, const int b) { return (a+b)/2; }

And changing the ctor to be something like:

Color(const Color &a, const Color &b)
:
rc(average(a.r(),b.r())),
rg(average(a.g(),b.g())),
rb(average(a.b(),b.b()))
{}

What do you think?

LR


Aug 30 '06 #9
LR wrote:
JoeC wrote:
>What is a handle?

Handles are often known as smart poiters.

I'm not sure that's correct. A quick look at foldoc seems to contradict
this.
http://foldoc.org/foldoc.cgi?query=handle&action=Search
>
They make dynamic binding
much easier by handling the memory allocation inside an object and the
user doesn't have to worry about all that.

I don't think that smart pointers are directly related to dynamic
binding in the way you suggest.

Please see http://foldoc.org/?query=dynamic+binding
>Is it possible you're talking about a different language, or something
that is implementation-specific?

I'm curious about this too. For example, Handles are used quite a bit
in Windows programming.
A "handle" is a generic programming term for any "opaque" type. An
opaque type can be thought of as a type whose structure and interface
is not known to the client. So all that a client can do with a handle
is to get one from an interface, hold on to it, and then to pass it
back to the interface when necessary. The interfaces for many OSes
typically declare system objects - windows, file descriptors and so
forth as "handles" in order to shield the client from dependence on the
particulars of the current, underlying implemention.

In C++ a handle is often declared as a typedef for a pointer to an
incomplete type:

struct IncompleteType;

typedef IncompleteType * Handle;

Greg

Aug 30 '06 #10
A "handle" is a generic programming term for any "opaque" type. An
opaque type can be thought of as a type whose structure and interface
is not known to the client. So all that a client can do with a handle
is to get one from an interface, hold on to it, and then to pass it
back to the interface when necessary. The interfaces for many OSes
typically declare system objects - windows, file descriptors and so
forth as "handles" in order to shield the client from dependence on the
particulars of the current, underlying implemention.

In C++ a handle is often declared as a typedef for a pointer to an
incomplete type:

struct IncompleteType;

typedef IncompleteType * Handle;

Greg
I created a simple handle. It takes care of all the pointer managment
for some dynamiclly bound objects. I can post some of the code so that
you can see what I am doing. It is all very simple.

class unit{
protected:
int locx;
int locy;

int atk;
int dfce;
void create();
public:
unit();
unit(std::istream);
~unit(){};
virtual void move();
virtual void attack();
virtual void display();
};

class hunit{

unit * p;
public:
hunit(char);
hunit(std::istream);
~hunit(){}
void move();
void attack();
void display();
};

hunit::hunit(char n){

switch(n){
case 'u':
p = new unit;
break;
case 'a':
p = new air;
break;
case 's':
p = new sea;
break;
}

}

hunit::hunit(std::istream){

}

void hunit::move(){
p->move();
}

void hunit::attack(){
p->attack();
}

void hunit::display(){
p->display();
}

I still have workd to do like adding copy control and destructors but
his is a start.

Aug 31 '06 #11
Here is my main program. I am using dynamic binding with no pointer
for the user to deal with. Still the idea of nodes is more advanced
but based on these principles. Read rumination on C++ they go into
great detail on this topic but is very complicated and dynamic binding
and handles must be understood first

#include<iostream>
#include<vector>

#include "hunit.h"
#include "unit.h"
#include "air.h"
#include "sea.h"

int main(){

std::vector<hunit>bde;
hunit u1('u');
hunit u2('s');
hunit u3('a');

bde.push_back(u1);
bde.push_back(u2);
bde.push_back(u3);
bde[0].attack();
bde[0].move();
bde[1].move();
bde[2].move();
bde[0].display();
bde[1].attack();

system("pause");

return 0;
}

Aug 31 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Greg | last post by:
Hi. I have a rather large xml document (object) that can have one or more nodes with a certain attribute throughout (at ANY depth, not at the same level necessarily). I need to find this...
3
by: LC | last post by:
Hello all, Ive been using the treeview and for testing purpose i have created 2 Parent Nodes and 5 child nodes within each parent node i.e.- CN = Child Node Parent Node - CN - CN - CN
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
3
by: juvi | last post by:
Hi, I have got a problem with Treeview.Nodes.Clear() under VB2005. When I have some nodes in my treeview and a force to clear() all nodes then it seems to work, because the nodes are not visible....
1
by: Christian Rühl | last post by:
hey! what i wanna do sounds very simple at first, but it turned out to be a real bone crusher... i want to check if a treeView node is checked and if a correspondent node in my xml config file...
1
by: Christian Rühl | last post by:
hey! what i wanna do sounds very simple at first, but it turned out to be a real bone crusher... i want to check if a treeView node is checked and if a correspondent node in my xml config file...
1
by: Daniel Rucareanu | last post by:
Hello, Does anybody knows how can you delete, in just one step, not using a loop, a subset of the child nodes of a given DOM parent node? The subset will be continous, so for example, if the...
0
by: georgerxz | last post by:
Download source code in C for learning Data structure implementation from http://zsoftwares.googlepages.com/CPrograms.html and http://zsoftwares.googlepages.com/DSFPrograms.htm Source...
10
by: John Rogers | last post by:
This code only counts the parent nodes or rootnodes in a treeview, how do you count all the nodes in a treeview? // one way int NodeCounter = 0; foreach (TreeNode currentNode in...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.