error: expected initializer before <type>

L

lovecreatesbea...

In the following function `HardwareStatusDb()', If its arguments are
declared as type of `string', I get:

main.cpp:5: error: expected initializer before ‘int’.

The error disappears when those arguments are declared as type of
`string &'.

Why am I getting this error?

Thank you for your time.

$ make
g++ -Wall -W -I/usr/include/mysql -I/usr/local/include/mysql++ -c -o
main.o main.cpp
main.cpp:5: error: expected initializer before ‘int’
make: *** [main.o] Error 1

$ cat HardwareStatusDb.cpp

#include <string>
using std::string;
#include "HardwareStatusDb.h"

//bool HardwareStatusDb(const string &database, const string &server,
// const string &username, const string &password, const string
&device)
bool HardwareStatusDb(string database, string server,
string username, string password, string device)
{
return true;
}

$ cat main.cpp

#include <string>
using std::string;
#include "HardwareStatusDb.h"

int main(int argc, char *argv[])
{
string s;
HardwareStatusDb(s, s, s, s, s);
return 0;
}

$ cat HardwareStatusDb.h

#ifndef HardwareStatusDb_h
#define HardwareStatusDb_h

#include <string>
using std::string;

//bool HardwareStatusDb(const string &database, const string &server,
// const string &username, const string &password, const string
&device);
bool HardwareStatusDb(string database, string server,
string username, string password, string device)

#endif

$
 
L

lovecreatesbea...

In the following function `HardwareStatusDb()', If its arguments are
declared as type of `string', I get:

    main.cpp:5: error: expected initializer before ‘int’.

The error disappears when those arguments are declared as type of
`string &'.
[...]

//bool HardwareStatusDb(const string &database, const string &server,
//      const string &username, const string &password, const string
&device);
bool HardwareStatusDb(string database, string server,
        string username,        string password, string device)

my bad, I forgot one semicolon at the end of the declaration.

I have another question, why the macros can not have the same names
with other identifiers? The macro names and the identifiers are in
different namespace (C's), right? The typedef names can be the same
as, for example, the structure names, right?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top