wont let me create a vector of my user defined class

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2008
Posts: 60
Reputation: chunalt787 is an unknown quantity at this point 
Solved Threads: 1
chunalt787 chunalt787 is offline Offline
Junior Poster in Training

wont let me create a vector of my user defined class

 
0
  #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:
  1. 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
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,580
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: 709
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

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

 
1
  #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 Quick reply to this message  
Join Date: Apr 2008
Posts: 60
Reputation: chunalt787 is an unknown quantity at this point 
Solved Threads: 1
chunalt787 chunalt787 is offline Offline
Junior Poster in Training

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

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

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC