Why is it not declared in scope?
I do not understand how to fix a huge about of scope relate errors. I have the correct headers needed. What do I need to do?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#ifndef PRIMARYINDEX_H_INCLUDED
#define PRIMARYINDEX_H_INCLUDED
#include <string>
#include <cstring>
#include <iostream>
#include <fstream>
class P_Node
{
friend class PrimaryIndex;
private:
std::string title;
int pos;
P_Node * next;
P_Node * prev;
public:
P_Node() : title("Hi"), pos(0)
{
next = prev = NULL;
}
P_Node(std::string my_title, int my_pos) : title(my_title), pos(my_pos)
{
next = prev = NULL;
}
};
class PrimaryIndex
{
friend class P_Node;
private:
P_Node * head;
P_Node * tail;
int size;
public:
PrimaryIndex() : size(0)
{
head = new P_Node(" ", -1);
tail = new P_Node("~", -1);
head->next = tail;
tail->prev = head;
}
~PrimaryIndex()
{
killList();
}
bool set_title_key(std::string my_title, int my_key);
void writePrimary();
void readPrimary();
void change_title(std::string new_title, int key);
int matchTitle(std::string inTitle, int key);
void killList();
void deletebyTitle();
void add_index(const std::string& key, int value);
void save(const std::string& filename) const;
void load(const std::string& filename);
void remove_index(const std::string& key);
int get_value(const std::string& key) const;
int get_count() const;
};
#endif
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#include "PrimaryIndex.h"
void PrimaryIndex::add_index(const std::string& key, int value)
{
//Check if index already exists, as no duplicates are allowed
for(int i = 0; i < count; i++)
{
if(index[i].key == key)
{
std::cerr << "Cannot add index, already exists." << std::endl;
return; //early return from function, can't do anything
}
}
//Otherwise, add it to the end
if(count < 25)
{
int pos = count;
index[pos] = PrimaryIndex::Entry(key, value);
count++;
}
else
{
std::cerr << "Cannot add index, index full." << std::endl;
}
}
void PrimaryIndex::remove_index(const std::string& key)
{
//search for matching key
for(int i = 0; i < count; i++)
{
//check if key matches
if(index[i].key == key)
{
//Move index entries after the remove one forward
//to fill the gap
for(int j = i; j < count - 1; j++)
{
index[j] = index[j + 1];
}
count--;
return;
}
}
std::cerr << "Cannot remove index, does not exist" << std::endl;
}
int PrimaryIndex::get_value(const std::string& key) const
{
for(int i = 0; i < count; i++)
{
if(index[i].key == key)
{
return index[i].value;
}
}
//Indicates not found
return -1;
}
int PrimaryIndex::get_count() const
{
return this->count;
}
void PrimaryIndex::load(const std::string& filename)
{
count = 0;
std::ifstream inFile(filename.c_str());
while(inFile.good() && !inFile.eof())
{
PrimaryIndex::Entry entry;
inFile >> entry.key >> entry.value;
index[count++] = entry;
}
}
void PrimaryIndex::save(const std::string& filename) const
{
std::ofstream outFile(filename.c_str());
for(int i = 0; i < count && outFile.good(); i++)
{
outFile << index[i].key << ' '
<< index[i].value << std::endl;
}
}
|
You have no variable named count.
Topic archived. No new replies allowed.