error: expected initializer before <type>

Discussion in 'C++' started by lovecreatesbea...@gmail.com, May 15, 2008.

  1. Guest

    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

    $
    , May 15, 2008
    #1
    1. Advertising

  2. Guest

    On May 15, 4:50 pm, ""
    <> wrote:
    > 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?
    , May 15, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. andrew browning
    Replies:
    16
    Views:
    15,473
    Artie Gold
    Mar 13, 2006
  2. Preben
    Replies:
    6
    Views:
    3,890
    Preben
    Sep 20, 2006
  3. Damien
    Replies:
    5
    Views:
    14,693
    Damien
    Dec 13, 2006
  4. Replies:
    5
    Views:
    23,687
  5. Jeff
    Replies:
    3
    Views:
    515
Loading...

Share This Page