I'm not a big fan of inline code. Just the way I was tought. All functions no matter even if the're one liners are declared in cpp. Just my personal preference :).
Ancient Dragon commented: Thanks for using code tags :) +21
I'm not a big fan of inline code. Just the way I was tought. All functions no matter even if the're one liners are declared in cpp. Just my personal preference :).
you have not written the implementation code for the functions in those two classes.
Thanx a lot. I was just experimenting, and thought it would not be necessary. Just a simple declaration should be enough. Learned something new today.
By the way the implementation was simple. Just made a cpp file with a cout message in the function.
namespace Test
{
void a::afunction ()
{
cout<<"this works"<<endl;
}
}
Hi there,
I have a simple problem.
I have a namespace with a couple of classes declared in a header file. The classes have functions but no body.
When I include the header file and try to call a function, i get the error unresolved external symbol referenced in function _main.
//headerfile
// forward declaration
namespace Test
{
class a;
class b;
}
namespace Test
{
class a
{
public:
void afunction ();
};
class b
{
public:
void bfunction ();
};
}
/// the main file
#include <iostream>
#include "headerfile.h"
using namespace std;
int main ()
{
Test::a* a = new Test::a();
a->afunction();
}
this is a cool movie on youtube you might want to check out that animates from the 1st to the 10th dimension
Problem finally solved. Basically the function return the value in the if statement if it is present in the array, if not it returns NULL that's located in the body of the function. The else statement was not needed. Thanks to everyone who helped me out on this one.
link* symbolTable::lookupArray(string value)
{
link* l;
for (l = symbol[hashfunction(value)]; l != NULL; l = l->next)
{
if (value == l->data)
{
cout<<"YES: "<<symbol[hashfunction(l->data)]->data<<endl;
return l;
}
}
cout<<"NO: "<<value<<endl;
return NULL;
}
Salem,
Thanks for the reply. I removed the if statement, it seems you are right, current can indeed never be null at that point so it's not needed. I've been working on what you said about my list never ending with a null pointer. So I started by filling my symboltable array with null values via a for statement. Next I loaded my linklist in the symboltable array. Now I do not get an error, but I want to have proof via a cout statement that the else statement is being accessed when there's no value matching the string i'm looking for. But the cout statement never comes in the output window
void symbolTable::emptySymbol ()
{
for (int i = 0; i < 9948; i++)
symbol [i]= NULL;
}
void symbolTable::loadSymbol()
{
link* current = first;
for (; current != NULL; current = current->next)
symbol [hashfunction(current->data)]= current;
}
link* symbolTable::lookupArray(string value)
{
link* l;
for (l = symbol[hashfunction(value)]; l != NULL; l = l->next)
{
if( l->data == value)
{
cout<<"\nFound it: "<<l->data<<endl;
return l;
}
else
{
cout<<"I'm in the else statement: "<<endl; // NEVER DISPLAYS
return NULL;
}
}
}
Any idea's anyone??
Hello,
I have problem witch i've been working on for a couple of days now with no real progress. The problem is that i'm trying to search trough a array of pointer for a certain value. If the value exist return that value to be used in another function, but if it doesn't exist return NULL. It's a simple if else statement, but the else part is not working correctly. The problem is with the function " link* symbolTable::lookupArray(string value)". If the value is in the symbol table it works fine, but not if the value is not present. It compiles fine, but i get a error screen and have to close the window. I'm using ms visual studio. Here my code brief.
struct link
{
string data;
int token;
link *next;
};
class key
{
protected:
link *first;
public:
key (): first(NULL){}
~key () {} // destructor
void addTailItem (string);
void addHeadItem (string);
void findItem ();
void displayItem ();
void fillItem ();
int hashfunction (string); // hash value from string
};
class symbolTable : public key // replace keyword with key
{
private:
static const int MAX_LEX_ARRAY = 999; // size of lexeme array
static const int MAX_SYM_ARRAY = 9948; // size of symbol table array prime 9949
link *symbol[MAX_SYM_ARRAY]; // pointer table array
string lexemeArray[MAX_LEX_ARRAY]; // array holding the lexemes
public:
symbolTable() {}
void loadSymbol (); // add keywords to symbol table
link* lookupArray(string); // find function for symbol table
void insertArray (string); // insert function …