943,657 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 601
  • C++ RSS
Nov 10th, 2008
0

wont let me create a vector of my user defined class

Expand Post »
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:
C++ Syntax (Toggle Plain Text)
  1. FrequencyTable.h:11: error: ISO C++ forbids declaration of ‘vector’ with no type
Class FrequencyNode
CPP Syntax (Toggle Plain Text)
  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
CPP Syntax (Toggle Plain Text)
  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
Reputation Points: 39
Solved Threads: 1
Junior Poster in Training
chunalt787 is offline Offline
84 posts
since Apr 2008
Nov 10th, 2008
2

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

The vector class is in the std namespace. Change vector<FrequencyNode> list; to std::vector<FrequencyNode> list; . You have other errors though.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Nov 10th, 2008
0

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

that worked thanks. Ya i know about the others. Im working on them now.
Reputation Points: 39
Solved Threads: 1
Junior Poster in Training
chunalt787 is offline Offline
84 posts
since Apr 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: string vs. variable
Next Thread in C++ Forum Timeline: Clothing size program has me racking my brain!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC