View Single Post
Join Date: Dec 2008
Posts: 21
Reputation: namehere05 is an unknown quantity at this point 
Solved Threads: 1
namehere05 namehere05 is offline Offline
Newbie Poster

Inheritance, and code not running

 
0
  #1
Dec 4th, 2008
Ah right! Im on my first steps on c++, What Im trying to do is
have this "basic node" class wich just take an id and from there
usign inheritance make "linked list node" and "binary tree node" classes my code so far looks like this

  1. void main()
  2. {
  3. sLink* pChainLink; //sLink stays for single list link
  4. sLink ChainLinkNo1 (pChainLink, 1);
  5. sLink ChainLinkNo2 (ChainLinkNo1, 2);
  6. sLink ChainLinkNo3 (ChainLinkNo2, 3);
  7.  
  8. sLink * tmp = ChainLinkNo3;
  9. while(tmp != 0){
  10. cout << tmp->Id();
  11. tmp = ChainLinkNo3.Next();
  12. }
  13.  
  14. }

and the other 2 headers

//sLink.h
class sLink : public Link
{
public:
 sLink (sLink* pNext, int id): Link(id), _pNext (pNext)   {}
  sLink * Next () const { return _pNext; }
private:
  sLink * _pNext;
};

  1. link.h //the basic node
  2. class Link
  3. {
  4. public:
  5. Link (int id): _id (id) {}
  6. int Id () const { return _id; }
  7. private:
  8. int _id;
  9. };

the compiler error says:

(red code position ) 'initializing' : cannot convert from 'Link *' to 'sLink *'

Some reason why's ... thanks
Last edited by namehere05; Dec 4th, 2008 at 11:12 pm.
Reply With Quote