Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ namespace not declared but it is?

Tags:

c++

namespaces

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.

like image 782
Tommy Avatar asked Feb 15 '11 13:02

Tommy


People also ask

Why there is no namespace in C?

Namespace is a feature added in C++ and not present in C. A namespace is a declarative region that provides a scope to the identifiers (names of the types, function, variables etc) inside it.

Does namespace exist in C?

No, C does not have a namespace mechanism whereby you can provide “module-like data hiding”.

What is the syntax for namespace?

Syntax of namespace declaration:namespace - is the keyword used to declare a namespace. namespacename - is the name given to the namespace. int m, n - are the variables in the namespace_name's scope.

What is namespace declaration in C++?

A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries.


1 Answers

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?

like image 140
Tom Avatar answered Oct 02 '22 15:10

Tom