2011-02-15 54 views
2

我有一個編譯時問題。新的C++,所以我相信它很簡單。我得到當前的錯誤。未聲明C++名稱空間,但它是?

diarydb.cpp: In function ‘bool editdate(int, mysqlpp::Connection&)’: diarydb.cpp:413: 
error: ‘format_tests’ has not been declared 

這裏

namespace format_tests { 
    bool testdateformat(string &date); 
    bool tesettimeformat(string &time); 
    bool lengthcheck(string &in,int length); 

} 

但diardby.cpp我宣佈format_tests與

bool format_tests::testdateformat(string &date){ 
    // tests format of dat input for MYSQL form at of YYYY-MM-DD 
    // Need to tweak regex to restrict 0 < MM < 12 and 0 < DD <31. 

    const boost::regex e("\\d{4}\\x2D\\d{2}\\x2D\\d{2}"); 
    return boost::regex_match(date,e); 
} 

這裏調用的編譯器compler。

bool dbsetget::editdate(int e_id,mysqlpp::Connection &con){ 

     char evdate[11]; 

    cout << "Input start time" << endl; 
    cin.getline(evdate,11,'\n'); // restrict legth of input with getline.lenght of input 

    string date = evdate; 

    if (format_tests::testdateformat(date)){ 
    mysqlpp::Query query = con.query(); 
    query <<"UPDATE main SET date="<< quote_only << date <<"WHERE d_Id ="<< e_id; 

    return query.exec(); 
    } 
    else 
    { 
     cerr << "Date not in correct format. YYYY-MM-DD "; 
     return false; 
    }; 
    } 

我不明白是什麼問題?我已經聲明瞭format_tests命名空間任何人都可以請引導我?

我相信這裏也有很多錯誤,但這個讓我很困惑。

+0

format_tests命名空間是在文件的前面聲明的而不是它的用法嗎? – Erik 2011-02-15 13:19:19

+2

這裏沒有足夠的信息來查明問題,所以我們必須猜測。也許命名空間format_tests在發生錯誤的地方不可見? – Dialecticus 2011-02-15 13:21:43

回答

1

看起來就像你有

format_tests::testdateformat(date) 

無法看到

namespace format_tests 
{ 
    bool testdateformat(string &date); 
}; 

已包含在testdateformat被declaired頭文件的文件?

相關問題