RSS Forums RSS

wont let me create a vector of my user defined class

Please support our C++ advertiser: Programming Forums
Thread Solved
Reply
Posts: 42
Reputation: chunalt787 is an unknown quantity at this point 
Solved Threads: 0
chunalt787 chunalt787 is offline Offline
Light Poster

wont let me create a vector of my user defined class

  #1  
Nov 10th, 2008
This is for a frequency table that will eventually allow me to build a Huffman coding tree. I want the class FrequencyTable to simply hold a vector of the type FrequencyNode however I keep getting an error about ISO forbiding the creation of the vector. Any ideas why?
Error:
FrequencyTable.h:11: error: ISO C++ forbids declaration of ‘vector’ with no type
Class FrequencyNode
  1. #ifndef FREQUENCY_NODE_H
  2. #define FREQUENCY_NODE_H
  3.  
  4. #include <iostream>
  5. #include <stdlib.h>
  6. #include <string>
  7.  
  8. class FrequencyNode {
  9. private:
  10. int frequency; //Key
  11. char character; //Element
  12.  
  13. public:
  14. FrequencyNode() //default constructor
  15. :character(0) {}
  16. FrequencyNode(int freqParam, char charParam) //constructor
  17. :frequency(freqParam), character(charParam) {}
  18.  
  19. int getKey() { return frequency; }
  20. char getChar() { return character; }
  21.  
  22. int incrimentKey() { frequency++; }
  23. int assignChar(char ch) { character = ch; }
  24.  
  25. };
  26.  
  27. #endif

Class FrequencyTable
  1. #include "FrequencyNode.h"
  2.  
  3. #include <vector>
  4.  
  5. #ifndef FREQUENCY_TABLE_H
  6. #define FREQUENCY_TABLE_H
  7.  
  8. class FrequencyTable {
  9.  
  10. private:
  11. vector<FrequencyNode> list;
  12.  
  13. public:
  14. int getlist() { return list; }
  15.  
  16. FrequencyNode getMin();
  17. bool charInTable(char ch);
  18.  
  19. };
  20.  
  21. //FUNCTION DEFINITIONS
  22. FrequencyNode FrequencyTable::getMin() {
  23. FrequencyNode smallest = list[0];
  24. for(int i = 0; i < list.size(); i++) {
  25. if(list[i].getKey() < smallest.getKey[i]) {
  26. smallest = list[i];
  27. } //end if statment
  28. } //end for loop
  29.  
  30. return smallest;
  31. }
  32.  
  33. bool FrequencyTable::charInTable(char ch) {
  34.  
  35. for(int i = 0; i < list.size(); i++) {
  36. if(list[i].getChar() == ch) {
  37. return true;
  38. } //end if statment
  39. } //end for loop
  40.  
  41. return false;
  42.  
  43. }
  44.  
  45. #endif

Thanks
AddThis Social Bookmark Button
Reply With Quote  
Posts: 7,460
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 676
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: wont let me create a vector of my user defined class

  #2  
Nov 10th, 2008
The vector class is in the std namespace. Change vector<FrequencyNode> list; to std::vector<FrequencyNode> list; . You have other errors though.
I'm here to prove you wrong.
Reply With Quote  
Posts: 42
Reputation: chunalt787 is an unknown quantity at this point 
Solved Threads: 0
chunalt787 chunalt787 is offline Offline
Light Poster

Re: wont let me create a vector of my user defined class

  #3  
Nov 10th, 2008
that worked thanks. Ya i know about the others. Im working on them now.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the C++ Forum
Views: 353 | Replies: 2 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:45 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC