受保护的声明

扫码查看
我猜MYSQL是一种不透明的类型。这意味着它没有在声明的 标头中定义(如stdio中的FILE)。 你不能直接实例化它,而是使用指针代替。 编译器抱怨mysql没有被宣布,而不是关于MYSQL的没有被定义。虽然未定义的类型 可能会导致所描述的错误消息(因此在 其他人之间),我不认为它'我很自然地认为这实际上已经发生了。发生了。 mkarja,请你发帖件file2.cpp,如果这个太长了,最小化的 版本仍会产生相同的错误?否则我们只能告诉你 mysql没有在你使用它的范围内声明。 它几乎肯定与mysql无关受到保护(然后 编译器会知道它已被声明,但会抱怨它不是可以访问的b $ b。 Markus 我猜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.cppbecausemysql was declared in file1.h under Protected.Thanks for all the help. I''m a bit lost with this.------mkarja 解决方案I guess MYSQL is an opaque type. It means it is not defined in theheader only declared (like FILE in stdio).You cannot instanciate it directly but use a pointer instead.Somathing like:Mysql* mysql=mysql_init();MichaelI guess MYSQL is an opaque type. It means it is not defined in theheader 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, notabout "MYSQL" not being defined. While it''s true that an undefined typemight result in the described error message (as a consequence and amongothers), I don''t think it''s natural to assume that this is what in fact hashappened.mkarja, could you please post file2.cpp or, if this is too long, a minimizedversion that still produces the same error? Otherwise we can only tell youthat 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 thecompiler would know it''s declared, but would complain that it is notaccessible).MarkusI guess MYSQL is an opaque type. It means it is not defined in theheader only declared (like FILE in stdio).You cannot instanciate it directly but use a pointer instead.Somathing like:Mysql* mysql=mysql_init();MichaelThanks 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 这篇关于受保护的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-27 18:22
查看更多