Passing pointers

Hi,

I'm making a wrapper class around SQLite, and I don't understand something about passing pointers.

The function to open a connection is this

1
2
3
4
5
6
int sqlite3_open_v2(
  const char *filename,   /* Database filename (UTF-8) */
  sqlite3 **ppDb,         /* OUT: SQLite db handle */
  int flags,              /* Flags */
  const char *zVfs        /* Name of VFS module to use */
);


My class has a member variable:

sqlite3* someDatabase;

If I do this someDatabase contains a valid database connection

1
2
3
4
void openConnection()
{
  sqlite3_open_v2(..., &someDatabase, ...); // someDatabase is a valid DB connection 
}


but if I do this, someDatabase has garbage in it

1
2
3
4
5
6
7
8
9
void init()
{
  openConnection(someDatabase); // someDatabase is NOT a valid DB connection
}

void openConnection(sqlite3* database)
{
  sqlite3_open_v2(..., &database, ...)
}


Can someone please explain or point to some reference for this case?
Say you have a function int foo(int i). If you call foo(x), do you expect the values of x to change? Normally only copies of parameters are sent to a function. If you want to modify the parameter, you'd write your function as int foo(int* xptr) or int foo(int& xref). Nothing changes with a pointer instead of integer. Your argument should have type sqlite3** or sqlite3*&.
You're right, thank you, sir
Topic archived. No new replies allowed.