我试图用C ++编写2001年编写的程序。当我在终端中运行安装脚本(即./setup
)时,我收到如下所示的错误。我已经搜索了一个解决方案,但我得到的想法是这种类型的错误是由更高版本的gcc即版本4及更高版本产生的。如何编辑编译器显示错误的代码,以便它在没有错误的情况下运行。
david@david-Satellite-C55-B:~$ cd Desktop/WebTraff/WebTraff && ./setup
Making executables in root directory
make: Nothing to be done for 'all'.
Making ProWGen
g++ -c -g stream.cc
stream.cc: In member function ‘unsigned int* RequestStream::GeneratePopularities()’:
stream.cc:104:39: error: array bound forbidden after parenthesized type-id
if ((popularity = new (unsigned int)[noofDistinctDocs]) == NULL)
^
stream.cc:104:39: note: try removing the parentheses around the type-id
stream.cc: In member function ‘unsigned int* RequestStream::GenerateFileSizes()’:
stream.cc:173:49: error: array bound forbidden after parenthesized type-id
unsigned int *filesizes = new (unsigned int)[noofDistinctDocs];
^
stream.cc:173:49: note: try removing the parentheses around the type-id
stream.cc: In member function ‘void RequestStream::GenerateUniqueDocs(Node*, int, Node*, int)’:
stream.cc:378:28: error: array bound forbidden after parenthesized type-id
uniqueDoc = new (Request*)[noofDistinctDocs];
^
stream.cc:378:28: note: try removing the parentheses around the type-id
Makefile:11: recipe for target 'stream.o' failed
make: *** [stream.o] Error 1
cp: cannot stat 'ProWGen': No such file or directory
Making CacheDriver
g++ -c CacheDriver.cc
g++ -c lru.cc
lru.cc: In constructor ‘Lru::Lru(unsigned int)’:
lru.cc:21:36: error: array bound forbidden after parenthesized type-id
if ( (hash_table = new (LruNode*)[MAX_SIZE]) == NULL)
^
lru.cc:21:36: note: try removing the parentheses around the type-id
lru.cc:23:61: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
ErrorMessage("Not enough memory to allocate hash table");
^
lru.cc: In member function ‘LruNode* Lru::get_new_node(unsigned int, unsigned int)’:
lru.cc:143:59: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
ErrorMessage("Cannot allocate more memory for new nodes");
^
lru.cc: In member function ‘void Lru::found_update(LruNode*)’:
lru.cc:270:66: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
if((loc != head)&&(succloc == NULL)) ErrorMessage("\nright here");
^
Makefile:8: recipe for target 'CacheDriver' failed
make: *** [CacheDriver] Error 1
cp: cannot stat 'CacheDriver': No such file or directory
Making popularity
gcc -o popularity main.o getch.o gettoken.o hash.o -lm
Making lrustack and freqsize
make: Nothing to be done for 'all'.
答案 0 :(得分:1)
new (unsigned int)[noofDistinctDocs]
是语法错误。我猜你的意思是:
new unsigned int[noofDistinctDocs]
分配unsigned int
数组。在代码中也会出现同样的错误。