C ++命名空间没有声明,但它是?

时间:2011-02-15 13:07:42

标签: c++ namespaces

我遇到编译时问题。 C ++的新手,所以我确信它很简单。我得到了当前的错误。

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

但是diardby.cpp我在这里声明了format_tests

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

}

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);
}

此处调用的编译器编译器。

  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命名空间有人可以指导我吗?

我确信这里也有很多错误,但这个让我很困惑。

1 个答案:

答案 0 :(得分:2)

看起来像你拥有的文件

format_tests::testdateformat(date)

看不到

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

您是否已将头文件包含在声明testdateformat的位置?

相关问题