C ++编译错误:在'{'标记之前的预期unqualified-id

时间:2014-04-29 12:43:31

标签: c++ cudd

我正在使用:

g++ -std=c++0x

编译器 我正在使用Cudd包http://vlsi.colorado.edu/~fabio/CUDD/开发一些项目,我想缓存一些结果,所以这里是我的缓存c ++代码

lrucache.h

#ifndef __LRUCACHE_H_
#define __LRUCACHE_H_

#include <iostream>//=> line 4
#include <vector>
#include <unordered_map>
#include "cudd.h"

using namespace std;


struct LRUCacheEntry
{
    unsigned int key;
    DdNode * data;
    LRUCacheEntry* prev;
    LRUCacheEntry* next;
};


class LRUCache
{
private:
    std::unordered_map<unsigned int, LRUCacheEntry *> _mapping;
    vector<LRUCacheEntry *> _freeEntries;
    LRUCacheEntry *head;
    LRUCacheEntry *tail;
    LRUCacheEntry *entries;
    DdManager *nfaobdd_manager;

public:
    LRUCache(size_t size, DdManager *nfaobdd_manager_ref);
    ~LRUCache();

    void put(unsigned int key, DdNode * data);

    DdNode * get(unsigned int key);

private:
    void detach(LRUCacheEntry* node);

    void attach(LRUCacheEntry* node);

};

#endif /*__LRUCACHE_H_*/

lrucache.c

#include <lrucache.h> //=>line 1


LRUCache::LRUCache(size_t size, DdManager *nfaobdd_manager_ref)
{

    entries = new LRUCacheEntry[size];

    for (int i=0; i<size; i++)
        _freeEntries.push_back(entries+i);

    head = new LRUCacheEntry;
    tail = new LRUCacheEntry;
    head->prev = NULL;
    head->next = tail;
    tail->next = NULL;
    tail->prev = head;

    nfaobdd_manager = nfaobdd_manager_ref;
}

LRUCache::~LRUCache()
{
    LRUCacheEntry* node = head->next;
    while(node!=tail){

            Cudd_RecursiveDeref(nfaobdd_manager,node->data);
    }
    delete head;
    delete tail;
    delete [] entries;
}

void LRUCache::put(unsigned int key, DdNode * data)
{   
    Cudd_ref(data);

    LRUCacheEntry* node = _mapping[key];
    if(node)
    {
        // refresh the link list
        detach(node);
        node->data = data;
        attach(node);
    }
    else{
        if ( _freeEntries.empty() )
        {
            node = tail->prev;
            detach(node);
            _mapping.erase(node->key);
            Cudd_RecursiveDeref(nfaobdd_manager,node->data);
            node->data = data;
            node->key = key;
            _mapping[key] = node;
            attach(node);
        }
        else{
            node = _freeEntries.back();
            _freeEntries.pop_back();
            node->key = key;
            node->data = data;
            _mapping[key] = node;
            attach(node);
        }
    }
}


DdNode * LRUCache::get(unsigned int key)
{
    LRUCacheEntry* node = _mapping[key];
    if(node)
    {
        detach(node);
        attach(node);
        return node->data;
    }
    else return NULL;
}


void LRUCache::detach(LRUCacheEntry* node)
{
    node->prev->next = node->next;
    node->next->prev = node->prev;
}
void LRUCache::attach(LRUCacheEntry* node)
{
    node->next = head->next;
    node->prev = head;
    head->next = node;
    node->next->prev = node;
}

nfaobdd.h

#ifndef __NFAOBDD_H_
#define __NFAOBDD_H_
.
.
#include <lrucache.h>//=>line 69
.
.
class NFAOBDD{
.
.
LRUCache *lrucache;
.
}
#endif /*__NFAOBDD_H_*/

nfaobdd.c

#include "nfaobdd.h" //=>line 10
.
.
lrucache = new LRUCache(100, manager);
.
.
/*character is of type unsigned int*/
DdNode * char_BDD = lrucache->get(character);
if(!char_BDD){
    /*calculate the value for char_BDD*/
    char_BDD = convert_decimal_to_BDD(character, manager, input_char); 
    /*cache the calculated value*/
    lrucache->put(character, char_BDD);
}
.
.
delete lrucache;

当我在项目中使用此缓存时,我收到以下错误,我无法理解。 我感谢任何帮助

In file included from /usr/include/c++/4.6/ios:45:0,
                 from /usr/include/c++/4.6/ostream:40,
                 from /usr/include/c++/4.6/iostream:40,
                 from /home/nadaossama/Dropbox/Master_Project/regex/regex/lrucache.h:4,
                 from nfaobdd.h:69,
                 from nfaobdd.c:10:
/usr/include/c++/4.6/bits/basic_ios.h: At global scope:
/usr/include/c++/4.6/bits/basic_ios.h:193:7: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.6/bits/basic_ios.h:194:7: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.6/bits/basic_ios.h: In member function ‘std::basic_ios<_CharT, _Traits>::operator void*() const’:
/usr/include/c++/4.6/bits/basic_ios.h:114:22: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.6/bits/basic_ios.h:114:22: error: expected ‘;’ before ‘{’ token
/usr/include/c++/4.6/bits/basic_ios.h:114:22: error: expected primary-expression before ‘)’ token
/usr/include/c++/4.6/bits/basic_ios.h:114:29: error: expected primary-expression before ‘?’ token
/usr/include/c++/4.6/bits/basic_ios.h: In member function ‘bool std::basic_ios<_CharT, _Traits>::operator!() const’:
/usr/include/c++/4.6/bits/basic_ios.h:118:22: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.6/bits/basic_ios.h:118:22: error: expected ‘;’ before ‘{’ token
/usr/include/c++/4.6/bits/basic_ios.h:118:22: error: expected primary-expression before ‘)’ token
In file included from /usr/include/c++/4.6/ostream:588:0,
                 from /usr/include/c++/4.6/iostream:40,
                 from /home/nadaossama/Dropbox/Master_Project/regex/regex/lrucache.h:4,
                 from nfaobdd.h:69,
                 from nfaobdd.c:10:
/usr/include/c++/4.6/bits/ostream.tcc: In member function ‘std::basic_ostream<_CharT, _Traits>::pos_type std::basic_ostream<_CharT, _Traits>::tellp()’:
/usr/include/c++/4.6/bits/ostream.tcc:244:15: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.6/bits/ostream.tcc:244:15: error: expected ‘)’ before ‘{’ token
/usr/include/c++/4.6/bits/ostream.tcc: In member function ‘std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::seekp(std::basic_ostream<_CharT, _Traits>::pos_type)’:
/usr/include/c++/4.6/bits/ostream.tcc:265:15: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.6/bits/ostream.tcc:265:15: error: expected ‘)’ before ‘{’ token
/usr/include/c++/4.6/bits/ostream.tcc: In member function ‘std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::seekp(std::basic_ostream<_CharT, _Traits>::off_type, std::ios_base::seekdir)’:
/usr/include/c++/4.6/bits/ostream.tcc:297:15: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.6/bits/ostream.tcc:297:15: error: expected ‘)’ before ‘{’ token
In file included from /usr/include/c++/4.6/istream:859:0,
                 from /usr/include/c++/4.6/iostream:41,
                 from /home/nadaossama/Dropbox/Master_Project/regex/regex/lrucache.h:4,
                 from nfaobdd.h:69,
                 from nfaobdd.c:10:
/usr/include/c++/4.6/bits/istream.tcc: In member function ‘std::basic_istream<_CharT, _Traits>::pos_type std::basic_istream<_CharT, _Traits>::tellg()’:
/usr/include/c++/4.6/bits/istream.tcc:829:19: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.6/bits/istream.tcc:829:19: error: expected ‘)’ before ‘{’ token
/usr/include/c++/4.6/bits/istream.tcc: In member function ‘std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::seekg(std::basic_istream<_CharT, _Traits>::pos_type)’:
/usr/include/c++/4.6/bits/istream.tcc:859:19: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.6/bits/istream.tcc:859:19: error: expected ‘)’ before ‘{’ token
/usr/include/c++/4.6/bits/istream.tcc: In member function ‘std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::seekg(std::basic_istream<_CharT, _Traits>::off_type, std::ios_base::seekdir)’:
/usr/include/c++/4.6/bits/istream.tcc:898:19: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.6/bits/istream.tcc:898:19: error: expected ‘)’ before ‘{’ token

1 个答案:

答案 0 :(得分:0)

Cudd包至少需要#include&#34; util.h&#34;和#include&#34; cudd.h&#34; 通过添加#include&#34; util.h&#34;到lrucahe.h问题解决了

谢谢大家的帮助