473,378 Members | 1,542 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,378 software developers and data experts.

[Merged] "'WordNode' does not name a type"? Help with Binary Search Tree

When I try to compile the below files, the complier says:
the WordNode h in BST.cpp: "WordNode" does not name a type
also in BST.cpp: "WordNode" undeclared, first use of this function

So, any advice? Sorry for the huge post, just wanted to make sure you can understand the problem. As it is, I'm lost.... I've included the WordNode header file, so why can't I create/use WordNode objects/methods (in BST)?

WordNode.h
Expand|Select|Wrap|Line Numbers
  1.  
  2. #ifndef RANDOM
  3. #define RANDOM
  4. #include <string> 
  5. #include <fstream>
  6. #include <fstream>
  7. #include <iostream>
  8. #include <dinput.h>
  9. #include "BST.h"
  10.  
  11. using namespace std;
  12.  
  13. class WordNode 
  14. public:
  15. WordNode(string name);
  16. string word;
  17. void getLeft( WordNode);
  18. void getRight (WordNode); 
  19. WordNode *left;
  20. WordNode *right;
  21. bool hasLeft;
  22. bool hasRight;
  23. friend ostream& operator<<(ostream& os, const WordNode& wn);
  24.  
  25. }; 
  26.  
  27. #endif
  28.  
  29. WordNode.cpp
  30. #include "WordNode.h"
  31. #include <string> 
  32. #include <fstream>
  33. #include <string> 
  34. #include <fstream>
  35. #include <vector>
  36. #include <iostream>
  37. #include <string>
  38. #include <stack>
  39. #include <queue>
  40. #include <dinput.h>
  41. #include "WordNode.h"
  42.  
  43. using namespace std;
  44.  
  45. WordNode::WordNode( string w)
  46. {
  47. word = w; 
  48. }
  49.  
  50. void WordNode::getLeft( WordNode lptr)
  51. {
  52. hasLeft = true;
  53. left = &lptr;
  54. }
  55.  
  56. void WordNode::getRight( WordNode rptr)
  57. {
  58. hasRight = true;
  59. right = &rptr;
  60. }
  61.  
  62. ostream& operator<<(ostream& os, const WordNode& wn)
  63. {
  64. os << wn.word;
  65. return os;
  66. };
  67.  
  68.  
Then......
BST.h
Expand|Select|Wrap|Line Numbers
  1.  #ifndef RANDOM 
  2. #define RANDOM
  3.  
  4. #include <string> 
  5. #include <fstream>
  6. #include <fstream>
  7. #include <iostream>
  8. #include <dinput.h>
  9. //#include "BST.h"
  10. #include "WordNode.h"
  11.  
  12. using namespace std;
  13.  
  14. class BST
  15. {
  16. public:
  17. BST();
  18. void insert();
  19. void print();
  20. WordNode h;
  21. //WordNode head;
  22. };
  23.  
  24. #endif
  25.  
And finally, BST.cpp

Expand|Select|Wrap|Line Numbers
  1.  #include <string> 
  2. #include <fstream>
  3. #include <fstream>
  4. #include <iostream>
  5. #include <dinput.h>
  6. #include "BST.h"
  7. #include "WordNode.h"
  8.  
  9. using namespace std;
  10.  
  11. BST::BST()
  12. {
  13. //head;
  14. WordNode h("hey");
  15.  
  16. };
  17.  
  18.  
Mar 23 '07 #1
7 2687
DeMan
1,806 1GB
I think part of the problem, is that both of your .h files use the same macro RANDOM to avoid being used more than once.....

You may be better to replace RANDOM (in both files I think - try to use obscure names that can't comde up in different circumstances) so that (for example) you could have:

BST.h
Expand|Select|Wrap|Line Numbers
  1. #ifndef _BST_H
  2. #define _BST_H
  3.  
  4. /* Declare protoypes etc */
  5.  
  6. #endif
  7.  
and in WordNode.h
Expand|Select|Wrap|Line Numbers
  1. #ifndef _WORDNODE_H
  2. #define _WRODNODE_H
  3.  
  4. /* Declare things */
  5.  
  6. #endif
  7.  
Mar 23 '07 #2
I'm trying to make a binary search tree for strings, and I've barely started but I already hit a wall. I've programmed in Java for a year or so and recently made the switch to C++ (for a class, college student). Anyway, I have WordNode.h and WordNode.cpp. Alone, they work fine (I decided not to use a struct, I'll need more flexiblity for this problem). But when I try and use a WordNode inside the BST.h and BST.cpp, it gives me the following error:

16 \BST.h `WordNode' does not name a type

Here are the files
Expand|Select|Wrap|Line Numbers
  1. WordNode.h
  2.  
  3.  
  4. #ifndef WORDNODE_H
  5. #define WORDNODE_H
  6. #include <string> 
  7. #include <iostream>
  8. #include "BST.h"
  9.  
  10. using namespace std;
  11.  
  12. class WordNode 
  13.   public:
  14.          WordNode();
  15.     WordNode(string name);
  16.     string word;
  17.     void getLeft( WordNode);
  18.     void getRight (WordNode); 
  19.     WordNode *left;
  20.     WordNode *right;
  21.     bool hasLeft;
  22.     bool hasRight;
  23.     friend ostream& operator<<(ostream& os, const WordNode& wn);
  24.  
  25. }; 
  26.  
  27. #endif
  28.  
  29.  
  30. WordNode.cpp
  31.  
  32. #include <string> 
  33. #include <iostream>
  34. #include "WordNode.h"
  35.  
  36. using namespace std;
  37.  
  38. WordNode::WordNode()
  39. {
  40. }
  41.  
  42. WordNode::WordNode( string w)
  43. {
  44.           word = w;                    
  45. }
  46.  
  47. void WordNode::getLeft( WordNode lptr)
  48. {
  49.      hasLeft = true;
  50.           left = &lptr;
  51. }
  52.  
  53.  
  54.  
  55.  
  56. void WordNode::getRight( WordNode rptr)
  57. {
  58.      hasRight = true;
  59.           right = &rptr;
  60. }
  61.  
  62.  
  63.  
  64.  ostream& operator<<(ostream& os, const WordNode& wn)
  65. {
  66.                 os << wn.word;
  67.                 return os;
  68. };
  69.  
  70.  
  71. BST.h
  72.  
  73. #ifndef BST_H
  74. #define BST_H
  75.  
  76. #include <string> 
  77. #include <iostream>
  78. #include "BST.h"
  79. #include "WordNode.h"
  80.  
  81. using namespace std;
  82.  
  83. class BST
  84. {
  85.       public:
  86.              BST();
  87.              WordNode head; <------------------------------------ERROR
  88. };
  89.  
  90. #endif
  91.  
  92.  
  93. BST.cpp
  94.  
  95. #include <string> 
  96. #include <iostream>
  97. #include "BST.h"
  98. #include "WordNode.h"
  99.  
  100. using namespace std;
  101.  
  102. WordNode head("hey");
  103.  
  104. BST::BST()
  105. {                 
  106. };
  107.  
  108.  
Any help would be greatly appreciated, and please go easy, I've only made 1 semi-difficult C++ program and about a dozen very easy ones (but none had two classes and two headers).
Mar 23 '07 #3
DeMan
1,806 1GB
Please do not double post....
Your previous post can be found here

If thwe answer provided does not sufficiently help, pos again being clear about where your difficulty lies
Mar 23 '07 #4
RedSon
5,000 Expert 4TB
Merged .
Mar 23 '07 #5
Very sorry, I'm new but I know double posts suck. I thought this problem was different enough and new title might help.
Mar 23 '07 #6
DeMan
1,806 1GB
Could you please highlight the difference in the two queries. Sorry I assumed they were both the same I can see some differences on more close inspection. As a general rule, if we are still talking about the same program, we'll keep it in the same thread.
If you need something totally off topic, you can open a new thread
Mar 24 '07 #7
DeMan
1,806 1GB
I don't think this is your problem, but you seem to be including BST.h in itself.....

I think you should be creating the WrodNode something like :

Expand|Select|Wrap|Line Numbers
  1. WordNode head = new WordNode("hey");
  2.  
Mar 24 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: aa | last post by:
I write to a text file, and when view the resulting file in Notepad, it shows "\t" as tabs correctly, but "\n" does not break the line. Instad it shows as a square. In Dreamweaver it shows OK....
2
by: Steven T. Hatton | last post by:
I'm still not completely sure what's going on with C++ I/O regarding the extractors and inserters. The following document seems a bit inconsistent:...
14
by: spike | last post by:
Im trying to write a program that should read through a binary file searching for the character sequence "\name\" Then it should read the characters following the "\name\" sequence until a NULL...
9
by: Xiangliang Meng | last post by:
Hi, all. I see a very strange fragment code today. Uint32 enum { a = 100; b = 200; }; NOTE: Uint32 is defined to be 'unsigned' in other source files.
13
by: dhughey | last post by:
I am using <script type="text/javascript"> function setAction(frm){ act = ''; for(x=0;x<frm.se.length;x++){ if(frm.se.checked){ act = frm.se.value; } }
1
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that...
4
by: lander | last post by:
I've read the page life cycle thing in msdn, still, i'm getting a bit confused of thinking how all the things are going under the hood... I know that when page loading, that the controls'...
4
by: KrazyKasper | last post by:
I'm a Novice User using Access 2003 Tables are via ODBC (i.e., cannot alter fields) I have a report that uses the field OrderRepName (text string) and is formatted as lastname, firstname,...
14
by: Anna | last post by:
I try to put 8 int bit for example 10100010 into one character of type char(1 octet) with no hope . Could anyone propose a simple way to do it? Thank you very much.
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.