Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   initilizer incmplete type (http://www.programmingforums.org/showthread.php?t=15719)

JD-Salinger Apr 28th, 2008 6:36 AM

initilizer incmplete type
 
i am doing this program which is a parser calculator but when i compile it there's an error which is "FunctionTable funtab has initializer but incomplete type", i am using codeblocks 8.02, and my program is kinda long. I think my algorithms are correct and the only problem is in the syntax or how i coded it... here's a snipet of the main function

:

  1. #include "Parser.h"
  2.  
  3. const int maxBuf=100;
  4. const int maxSymbols=40;
  5.  
  6.  
  7. int main()
  8. {
  9.  
  10.  
  11.     char buf[maxBuf];
  12.     Status status;
  13.     SymbolTable symTab(maxSymbols);
  14.     FunctionTable funTab(symTab,funArr);
  15.     Store store(maxSymbols,symTab);
  16.  
  17.     do
  18.     {
  19.         cout<<">"; //prompt
  20.         cin.getline(buf,maxBuf);
  21.         Scanner scanner(buf);
  22.         Parser parser(scanner,store,funTab,symTab);
  23.         status=parser.Eval();
  24.     }while(status!=stQuit);
  25.  
  26.     return 0;
  27.  
  28. }


its compiled as a one project, thats why it only had one header file, it is composed of 9 source files and 8 header files. i suppose that the problem is in the function table source file or function table header file...

FunTab.h
:

  1. #include <cmath>
  2. class SymbolTable; //forward declaration
  3.  
  4. typedef double (*PtrFun) (double);
  5. const int maxIdFun = 16;
  6.  
  7. class FunctionEntry
  8. {
  9.     public:
  10.         PtrFun pFun;
  11.         char* strFun;
  12. };
  13.  
  14.  
  15. extern FunctionEntry funArr[];
  16.  
  17. class FunctionTable
  18. {
  19.     public:
  20.         FunctionTable(SymbolTable& symTab,FunctionEntry funArr[]);
  21.         int Size() const {return _size;}
  22.         PtrFun GetFun (int id) {return _pFun[id];}
  23.     private:
  24.         PtrFun _pFun[maxIdFun];
  25.         int    _size;
  26. };


FunTab.cpp

:

  1. #include "SymTab.h"
  2. #include "FunTab.h"
  3.  
  4. #include <cmath>
  5. #include <cstring>
  6. #include <cassert>
  7. using namespace std;
  8.  
  9. double CoTan(double x)
  10. {
  11.     double y=tan(x);
  12.     if(y==0)
  13.     {
  14.         cout<<"cotan of "<<x<<" undefined\n";
  15.         return HUGE_VAL;
  16.     }
  17.     return 1.0/y;
  18. };
  19.  
  20.  
  21. FunctionEntry funArr [maxIdFun] =
  22. {
  23.     log,  "log",
  24.     log10,"log10",
  25.     exp,  "exp",
  26.     sqrt, "sqrt",
  27.     sin,  "sin",
  28.     cos,  "cos",
  29.     tan,  "tan",
  30.     CoTan,"cotan",
  31.     sinh, "sinh",
  32.     cosh, "cosh",
  33.     tanh, "tanh",
  34.     asin, "asin",
  35.     acos, "acos",
  36.     atan, "atan",
  37.     0,    ""
  38. };
  39.  
  40.  
  41. FunctionTable::FunctionTable(SymbolTable& symTab,FunctionEntry funArr[])
  42.     :_size(0)
  43. {
  44.     for(int i=0; i<maxIdFun; ++i)
  45.     {
  46.         int len=strlen(funArr[i].strFun);
  47.         if(len==0)
  48.             break;
  49.         _pFun[i]=funArr[i].pFun;
  50.         cout<< funArr[i].strFun<<endl;
  51.         int j=symTab.ForceAdd(funArr[i].strFun,len);
  52.         assert(i==j);
  53.         ++_size;
  54.     }
  55. }


should i provide a Link to the whole program? thank you very much...

Jabo Apr 28th, 2008 12:41 PM

Re: initilizer incmplete type
 
:

  1. int Size() const {return _size;}


This doesn't look right to me, you have the const keyword without a name.

Jessehk Apr 28th, 2008 4:19 PM

Re: initilizer incmplete type
 
Quote:

Originally Posted by Jabo (Post 144459)
:

  1. int Size() const {return _size;}


This doesn't look right to me, you have the const keyword without a name.

Jabo, the const there indicates that when the method is called, it does not modify the object.

mbd Apr 28th, 2008 5:50 PM

Re: initilizer incmplete type
 
zip up the source and attach it

JD-Salinger Apr 28th, 2008 8:23 PM

Re: initilizer incmplete type
 
Thanks for the reply: here are the files
rs link:
PARSER.ZIP

Cache Apr 29th, 2008 2:58 AM

Re: initilizer incmplete type
 
You need to:
:

#include "Scanner.h"
#include "SymTab.h"
#include "FunTab.h"
#include "Store.h"

in either Parser.h or main.cpp

#include <cassert> in PTree.h

And there's an error in SymTab.cpp at line 54 about calling strcmp with 3 arguments. No doubt you meant to usestrncmp.

JD-Salinger Apr 29th, 2008 5:28 AM

Re: initilizer incmplete type
 
Quote:

Originally Posted by Cache (Post 144492)
You need to:
:

#include "Scanner.h"
#include "SymTab.h"
#include "FunTab.h"
#include "Store.h"

in either Parser.h or main.cpp

#include <cassert> in PTree.h

And there's an error in SymTab.cpp at line 54 about calling strcmp with 3 arguments. No doubt you meant to usestrncmp.

THanks a lot cache!!!! I am so STUPID!!!!!!!!!!!!!!!!!!! whoooo!!!! i just need to include those files.... and i checked the scanner.h header file... there's still some error in the ACCEPT method ill give it another check... thanks again... a big help


All times are GMT -5. The time now is 9:25 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC