受保护的声明 [英] Protected declaration

查看:84
本文介绍了受保护的声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有文件,让我们说file2.cpp #includes file1.h。

file1.h看起来像这个。有点剥离的版本。

-------------------------------------- -------

#include< mysql / mysql.h>


class file1

{

public:

file1();

~file1();

protected:

MYSQL mysql;

}

----------------------------- ----------------

在file2.cpp中我有一行:mysql_autocommit(& mysql,0);


g ++给出了一个错误:错误:'mysql''未在此范围内声明。


我不能在这种情况下使用mysql file2.cpp

因为

mysql在file1.h中声明受保护。


感谢所有帮助。我有点迷失了。


------

mkarja

解决方案

mkarjaaécrit:





我有文件,让's。说file2.cpp #includes file1.h。

file1.h看起来像这样。有点剥离的版本。

-------------------------------------- -------

#include< mysql / mysql.h>


class file1

{

public:

file1();

~file1();

protected:

MYSQL mysql;

}

----------------------------- ----------------

在file2.cpp中我有一行:mysql_autocommit(& mysql,0);


g ++给出了一个错误:错误:'mysql''未在此范围内声明。


我不能在这种情况下使用mysql file2.cpp

因为

mysql是在受保护的file1.h中声明的。



我猜MYSQL是一种不透明的类型。这意味着它没有在声明的

标题中定义(如stdio中的FILE)。

你不能直接实例化它而是使用指针代替。


类似于:

Mysql * mysql = mysql_init();


Michael

你好


Michael DOUBEZ写道:


mkarja a ?? crit:


>在file2.cpp中我有一行:mysql_autocommit(& mysql,0);

g ++给出错误:错误:''mysql''在这个范围内没有声明。

我不能在这个案例中使用mysql来自file2.cpp
因为在file1.h下声明了mysql受保护的。



我猜MYSQL是一种不透明的类型。这意味着它没有在声明的

标头中定义(如stdio中的FILE)。

你不能直接实例化它,而是使用指针代替。



编译器抱怨mysql没有被宣布,而不是关于MYSQL的
没有被定义。虽然未定义的类型

可能会导致所描述的错误消息(因此在

其他人之间),我不认为它'我很自然地认为这实际上已经发生了。
发生了。


mkarja,请你发帖件file2.cpp,如果这个太长了,最小化的

版本仍会产生相同的错误?否则我们只能告诉你

mysql没有在你使用它的范围内声明。


它几乎肯定与mysql无关受到保护(然后

编译器会知道它已被声明,但会抱怨它不是可以访问的b $ b。


Markus


On 2 loka,11:39,Michael DOUBEZ< michael.dou ... @ free.frwrote:
< blockquote class =post_quotes>
mkarjaaécrit:




我有文件,让我们说file2.cpp #includes file1.h。

file1.h看起来像这样。有点剥离的版本。

-------------------------------------- -------

#include< mysql / mysql.h>


class file1

{

public:

file1 ();

~file1();

受保护:

MYSQL mysql;

}

---------------------------------------------

在file2.cpp中我有一行:mysql_autocommit(& mysql,0);


g ++给出错误:错误:''mysql''未在此范围内声明。


我不能在这种情况下使用mysql来自file2.cpp

,因为

mysql是在受保护的file1.h中声明的。



我猜MYSQL是一种不透明的类型。这意味着它没有在声明的

标题中定义(如stdio中的FILE)。

你不能直接实例化它而是使用指针代替。


类似于:

Mysql * mysql = mysql_init();


Michael



感谢您的回答。

我试图将文件中的:Mysql * mysql = mysql_init();

保存在file1.h下,但它没有没有帮助。同样的错误仍然存​​在。


----

mkarja


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.

Thanks for all the help. I''m a bit lost with this.

------
mkarja

解决方案

mkarja a écrit :

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


Hi

Michael DOUBEZ wrote:

mkarja a ??crit :

>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.

The compiler is complaining about "mysql" not being declared, not
about "MYSQL" not being defined. While it''s true that an undefined type
might result in the described error message (as a consequence and among
others), I don''t think it''s natural to assume that this is what in fact has
happened.

mkarja, could you please post file2.cpp or, if this is too long, a minimized
version that still produces the same error? Otherwise we can only tell you
that mysql was not declared in the scope in which you are using it.

It almost certainly has nothing to do with mysql being protected (then the
compiler would know it''s declared, but would complain that it is not
accessible).

Markus


On 2 loka, 11:39, Michael DOUBEZ <michael.dou...@free.frwrote:

mkarja a écrit :

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


这篇关于受保护的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆