Re: Protected declaration
On 2 loka, 12:01, mkarja <mka...@gmail.com> wrote:
On 2 loka, 11:39, Michael DOUBEZ <michael.dou...@free.fr> wrote:
mkarja a =E9crit :
Hi,
I have file, let's say file2.cpp that #includes file1.h.
file1.h looks something like this. Somewhat stripped version.
---------------------------------------------
#include <mysql/mysql.h>
class file1
{
public:
file1();
~file1();
protected:
MYSQL mysql;
}
---------------------------------------------
In file2.cpp I have a line: mysql_autocommit(&mysql, 0);
The g++ gives an error: error: 'mysql' was not declared in this scope.
Shouldn't I be able to use mysql in this case from the file2.cpp
because
mysql was declared in file1.h under Protected.
I guess MYSQL is an opaque type. It means it is not defined in the
header only declared (like FILE in stdio).
You cannot instanciate it directly but use a pointer instead.
Somathing like:
Mysql* mysql=mysql_init();
Michael
Thanks for the answer.
I tried to put the: Mysql* mysql=mysql_init();
in file1.h under Protected, but it didn't help. The same error still.
----
mkarja
Sorry Markus, didn't see your message until I had posted.
There's really nothing spectacular about file2.cpp, but I'll post
stripped
version of it here so you can mayby see why it gives this error.
There's only some if, for etc. stuff in it also, but they are after
that
mysql_autocommit(&mysql, 0); line.
-----------------------------
#include "file1.h"
#include "Poco/Exception.h"
#include "Poco/Util/Application.h"
#include <string>
using Poco::Util::Application;
file2::file2():
_Id(0),
_GroupId(0),
_userId(0)
{
}
file2::~file2()
{
}
int file2::saveToDatabase()
{
int is_client=0;
mysql_autocommit(&mysql, 0);
if (strcmp(getOwner().c_str(),"CLIENT")==0)
{
is_client=1;
}
else
{
Application::instance().logger().debug("Coming server ");
}
}
-----------------------------
Hope this helps a bit. That stripped code also gives the same error.
----
mkarja