| | |
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: 61
Reputation:
Solved Threads: 1
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: Class FrequencyNode
Class FrequencyTable
Thanks
Error:
C++ Syntax (Toggle Plain Text)
FrequencyTable.h:11: error: ISO C++ forbids declaration of ‘vector’ with no type
CPP Syntax (Toggle Plain Text)
#ifndef FREQUENCY_NODE_H #define FREQUENCY_NODE_H #include <iostream> #include <stdlib.h> #include <string> class FrequencyNode { private: int frequency; //Key char character; //Element public: FrequencyNode() //default constructor :character(0) {} FrequencyNode(int freqParam, char charParam) //constructor :frequency(freqParam), character(charParam) {} int getKey() { return frequency; } char getChar() { return character; } int incrimentKey() { frequency++; } int assignChar(char ch) { character = ch; } }; #endif
Class FrequencyTable
CPP Syntax (Toggle Plain Text)
#include "FrequencyNode.h" #include <vector> #ifndef FREQUENCY_TABLE_H #define FREQUENCY_TABLE_H class FrequencyTable { private: vector<FrequencyNode> list; public: int getlist() { return list; } FrequencyNode getMin(); bool charInTable(char ch); }; //FUNCTION DEFINITIONS FrequencyNode FrequencyTable::getMin() { FrequencyNode smallest = list[0]; for(int i = 0; i < list.size(); i++) { if(list[i].getKey() < smallest.getKey[i]) { smallest = list[i]; } //end if statment } //end for loop return smallest; } bool FrequencyTable::charInTable(char ch) { for(int i = 0; i < list.size(); i++) { if(list[i].getChar() == ch) { return true; } //end if statment } //end for loop return false; } #endif
Thanks
![]() |
Other Threads in the C++ Forum
- Previous Thread: string vs. variable
- Next Thread: Clothing size program has me racking my brain!
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






