Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,572 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,673 people online right now. Registration is fast and FREE... Join Now!




Returning Inherited Pointers Issues(RESLOVED)

 
Reply to this topicStart new topic

Returning Inherited Pointers Issues(RESLOVED), Doing some clean up

MikeRaines
30 Oct, 2007 - 09:00 AM
Post #1

D.I.C Head
**

Joined: 30 Oct, 2007
Posts: 76



Thanked: 1 times
My Contributions
I am taking apart some old code and breaking it up into header and cpp files from my old days when I would code in one ugly block.

Creating a repository to hold different data structures and commonly used files of mine, using as much inheritance as possible.

When creating my base Node class and it's children ie(treeNode, listNode) I am having an issue returning the base left and right pointers, im sure it's something simple and stupid but this has had me triped up for about 30 minutes so I figured I would ask.

Errors:
Error 1 error C2440: 'return' : cannot convert from 'Node *' to 'treeNode *'
Error 3 error C2440: 'return' : cannot convert from 'Node *' to 'dictionaryNode *'

Node:Header
CODE

#include <iostream>
#include <string>
#include <istream>
using namespace std;
#ifndef NODE
#define NODE

class Node
{
public:
    Node *Left, *Right;
    Node();
    void setLeft(Node *n);
    void setRight(Node *n);
    Node * getLeft();
    Node * getRight();
};
#endif


Node:.cpp
CODE

#include <iostream>
#include <string>
#include <fstream>
#include "Node.h"
using namespace std;
Node::Node()
{
    Left=NULL;
    Right=NULL;
}
void Node::setLeft(Node *n)
{
    Left = n;
}
void Node::setRight(Node *n)
{
    Right = n;
}
Node * Node::getLeft()
{
    return Left;
}
Node * Node::getRight()
{
    return Right;
}


TreeNode:Header
CODE

#include <iostream>
#include <string>
#include <istream>
#include "Node.h"
using namespace std;
#ifndef TREENODE
#define TREENODE

class treeNode : public Node
{
public:
    treeNode *Parent;
    treeNode();
    void setParent(treeNode *n);
    treeNode * getParent();
};
#endif


TreeNode:.cpp
CODE

#include <iostream>
#include <string>
#include <fstream>
#include "treeNode.h"
using namespace std;

treeNode::treeNode(int Shares, double Price):Node()
{
    Parent = NULL;
}
treeNode * treeNode::getParent()
{
    return Parent;
}
void treeNode::setParent(treeNode *n)
{
    Parent = n;
}


Same problem different child for all when interacting with the Left and Right base pointers.

Any ideas would be appreciated.

I have been using the online code communities for a while, and this site has been the one I have found the most helpful so I finally decided to register and get a little involved.

Thanks again,
Mike

This post has been edited by MikeRaines: 30 Oct, 2007 - 08:39 PM
User is offlineProfile CardPM
+Quote Post

jjhaag
RE: Returning Inherited Pointers Issues(RESLOVED)
30 Oct, 2007 - 11:46 AM
Post #2

me editor am smartastic
Group Icon

Joined: 18 Sep, 2007
Posts: 1,789



Thanked: 2 times
Dream Kudos: 775
Expert In: C,C++

My Contributions
Hi Mike,

Glad you seem to have resolved your issues with this program. Could you please post the resolution that you came up with so that others could benefit from the solution? Thanks,

-jjh
User is offlineProfile CardPM
+Quote Post

MikeRaines
RE: Returning Inherited Pointers Issues(RESLOVED)
30 Oct, 2007 - 03:54 PM
Post #3

D.I.C Head
**

Joined: 30 Oct, 2007
Posts: 76



Thanked: 1 times
My Contributions
ISSUE RESOLVED:(Fix)
The fix was pretty simple, I converted my base Node class into a template.

This allows gets and sets to be told to return the node type of one of the children.

Just required a little sitting around and staring at the screen to figure out.

Hope this helps someone else out.

This post has been edited by MikeRaines: 30 Oct, 2007 - 03:55 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 10:26PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month