Tommy
Tommy

Reputation: 607

C++ namespace not declared but it is?

I'm having a compile time problem. New to C++ so I'm sure it's simple. I am gettign the current error.

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

but diardby.cpp I have declared format_tests here

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

}

with

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

the compiler compler of the call here.

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

I don't understand what the problem is? I have declared format_tests namespace Can anyone please guide me?

I'm sure there are plenty of to mistakes in here too but this one has got me pretty confused.

Upvotes: 11

Views: 23147

Answers (1)

Tom
Tom

Reputation: 5309

Looks like the file in which you have

format_tests::testdateformat(date)

cannot see the

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

Have you included the header file where the testdateformat is declaired?

Upvotes: 11

Related Questions