hey guys can anyone help me with this?
I am getting this error:
[email protected] $ make
g++ -I ../include *.cpp -o assignment3.exe
Undefined symbols:
"GenStack<char>::~GenStack()", referenced from:
DelimChecker<char>::~DelimChecker()in cc3z2PH0.o
DelimChecker<char>::~DelimChecker()in cc3z2PH0.o
"GenStack<char>::GenStack()", referenced from:
DelimChecker<char>:elimChecker()in cc3z2PH0.o
"DelimChecker<char>::check(std::basic_string<c har, std::char_traits<char>, std::allocator<char> >)", referenced from:
_main in cc3z2PH0.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [all] Error 1
main.cpp
Code:
#include "DelimChecker.h"
using namespace std;
int main(int argc, char** argv)
{
string sourceFile(argv[1]);
DelimChecker<char>* test = new DelimChecker<char>();
test->check(sourceFile); //i think error is happening here
return 0;
}
GenStack.h
Code:
/**header file for GenStack class
* @author Bryce Miller
* @author [email protected]
* @version 1.0
*/
#ifndef GEN_STACK_H
#define GEN_STACK_H
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <exception>
using namespace std;
template <class T>
class GenStack
{
private:
unsigned int m_LIMIT;
int m_size;
T* m_theStack;
int m_top;
public:
GenStack();
GenStack(int theSize);
virtual ~GenStack();
void push(T data);
T pop();
T peek();
bool isEmpty();
bool isFull();
int getSize();
};
#endif
GenStack.cpp
Code:
/**stack class based on arrays
* @author Bryce Miller
* @author [email protected]
* @version 1.0
*/
#include "GenStack.h"
/** The default constructor
* creates stack with generic size limit 10
* @param none
* @return no return value
* @exception none
*/
template <class T>
GenStack<T>::GenStack()
{
m_LIMIT = 10;
m_size = 0;
m_theStack = new T[m_LIMIT];
m_top = -1;
}
/** User-defined array size constructor -
* Custom sized stack
* @param allocate The amount of memory to allocate as an array
* @return no return value
* @exception none
*/
template <class T>
GenStack<T>::GenStack(int theSize)
{
m_LIMIT = theSize;
m_theStack = new T[m_LIMIT];
m_top = -1;
}
/** The destructor: deletes the stack
* @param none
* @return no return value
* @exception none
*/
template <class T>
GenStack<T>::~GenStack()
{
delete[] m_theStack;
}
/** push method
* @param data: a piece of data to add to the stack
* @return no return value
* @exception none
* increments the size of stack
*/
template <class T>
void GenStack<T>::push(T data)
{
m_theStack[++m_top] = data;
++m_size;
}
/** pop method
* @param none
* @return the top piece of data on the stack
* @exception none
* decrements the size
*/
template <class T>
T GenStack<T>::pop()
{
--m_size;
return m_theStack[m_top--];
}
/** peek method
* @param none
* @return shows the top piece of data of the stack
* @exception none
*/
template <class T>
T GenStack<T>::peek()
{
return m_theStack[m_top];
}
/** isEmpty method
* @param none
* @return boolean, if the size is equal to 0
* @exception none
*/
template <class T>
bool GenStack<T>::isEmpty()
{
return (m_size == 0);
}
/** isFull Method
* @param none
* @return boolean, if size equals the LIMIT
* @exception none
*/
template <class T>
bool GenStack<T>::isFull()
{
return (m_size == m_LIMIT);
}
/** getSize Method
* @param none
* @return int, the size
* @exception none
*/
template <class T>
int GenStack<T>::getSize()
{
return m_size;
}
DelimChecker.h
Code:
/**header file for DelimChecker
* @author Bryce Miller, Stephen Ciauri
* @author [email protected]
* @version 1.0
*/
#ifndef DELIM_CHECKER_H
#define DELIM_CHECKER_H
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <exception>
#include "GenStack.h"
using namespace std;
template <class T>
class DelimChecker: public GenStack<T>
{
private:
public:
void check(string file);
bool isDelim(char c); //done MAYBE
bool isOpen(char c); //done
char getComplement(T theDelim); //done
};
#endif
DelimChecker.cpp
Code:
/**checks the source code for open ended delims
* @author Bryce Miller
* @author [email protected]
* @version 1.0
*/
#include "DelimChecker.h"
template <class T>
void DelimChecker<T>::check(string file)
{
char c;
string temp;
int line = 0;
GenStack<T> stack = new GenStack<T>();
try
{
ifstream theFile (file.c_str());
char tempChar[256];
if (theFile.is_open())
{
while (theFile.good())
{
theFile.getline(tempChar, 256);
++line;
//loops throught each char in the line
for (int i = 0; i < temp.length(); ++i)
if(isDelim(c=temp[i]))
{
try { // adds all open brackets to the stack
if (isOpen(c))
stack.push(c);
//removes if brackets match up
else if(stack.peek() == ((T)getComplement(c)))
stack.pop();
else { //error if brackets dont match up
cout<<"ERROR: line : "<<line<<" : type mismatch"<<endl;
cout<<"expected "<<getComplement(stack.peek())<<", got "<<c<<endl;
exit(0);
}
} catch (...) { //error if extra closed bracket is missing an open bracket
cout<<"ERROR: line : "<<line<<" : type mismatch"<<endl;
cout<<c<<" is extra or missing "<<getComplement(c)<<endl;
exit(0);
}
}
}
}
theFile.close();
}
catch (...)
{
cout<<"Error."<<endl;
}
if (stack.getSize() > 0) {
cout<<"ERROR: line : "<<line<<" : unexpected end-of-file"<<endl;
try {
cout<<"expected "<<getComplement(stack.peek())<<endl;
}catch (...) {}
exit(0);
}
cout<<"no errors!"<<endl;
}
/** isDelim method, checks if the char is one of the delims
* @param char, c to check if the char is a delim
* @return bool, true if it is one of the delims
* @exception none
*/
template <class T>
bool DelimChecker<T>::isDelim(char c)
{
int length;
char delims[] = {'(', ')', '{', '}', '[', ']'};
length = (sizeof delims)/(sizeof(char)); //dertermines length of array
for (int i = 0; i < length; ++i)
{
if (c == delims[i])
{
return true;
}
}
return false;
}
/** isOpen method, checks if the delim was left open
* @param char, the delim to check
* @return bool, true if one of the delims is left open
* @exception none
*/
template <class T>
bool DelimChecker<T>::isOpen(char c)
{
int length;
char delims[] = {'(', '{', '['};
length = (sizeof delims)/(sizeof(char)); //dertermines length of array
for (int i = 0; i < length; ++i)
{
if (c == delims[i])
{
return true;
}
}
return false;
}
/** getComplement method, will get the brakets significant other
* @param T, theDelim to find the complement of
* @return char, the opporsite of the bracket in the param
* @exception none
*/
template <class T>
char DelimChecker<T>::getComplement(T theDelim)
{
char result = 0;
int length;
char delims[] = {'(', ')', '{', '}', '[', ']'};
length = (sizeof delims)/(sizeof(char)); //dertermines length of array
for (int i = 0; i < length; ++i)
{
if (theDelim == (delims[i]))
{
if (i%2 == 0)
{
result = delims[i+1];
}
else
{
result = delims[i-1];
}
}
}
return result;
}
thank you in advance!