By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,148 Members | 765 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,148 IT Pros & Developers. It's quick & easy.

error: expected initializer before <type>

P: n/a
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

$

Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On May 15, 4:50*pm, "lovecreatesbea...@gmail.com"
<lovecreatesbea...@gmail.comwrote:
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?
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.