DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   wont let me create a vector of my user defined class (http://www.daniweb.com/forums/thread156468.html)

chunalt787 Nov 10th, 2008 5:30 pm
wont let me create a vector of my user defined class
 
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
#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
#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

Narue Nov 10th, 2008 5:33 pm
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.

chunalt787 Nov 10th, 2008 5:39 pm
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.


All times are GMT -4. The time now is 1:46 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC