试图编译以下代码我得到这个编译错误,我该怎么办?
ISO C++禁止获取非限定或带括号的非静态成员函数的地址,以形成指向成员函数的指针.
class MyClass {
int * arr;
// other member variables
MyClass() { arr = new int[someSize]; }
doCompare( const int & i1, const int & i2 ) { // use some member variables }
doSort() { std::sort(arr,arr+someSize, &doCompare); }
};
Run Code Online (Sandbox Code Playgroud) 我的问题是,当我想创建一个下载的库时,我从GCC得到一些奇怪的编译错误,编译器要求纠正的代码似乎是正确的.
错误都是这样的:
Catalogue.h:96:错误:'strlen'没有依赖于模板参数的参数,因此'strlen'的声明必须是可用的
这是第96行的代码:
GaCatalogueEntry(const char* name, T* data)
{
if( name )
{
_nameLength = (int)strlen( name ); // LINE 96
// copy name
_name = new char[ _nameLength + 1 ];
strcpy( _name, name ); // LINE 100: similar error
_data = data;
return;
}
_name = NULL;
_nameLength = 0;
_data = NULL;
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能解决这些编译错误?
访问方法"foo"的不同线程是否有自己的局部变量副本,还是需要使此方法同步?
class X {
static returnType foo( Object arg) {
Object localvar;
// perform some calculation based on localvar and arg.
// no non-local variable is used i.e: this is a utility method.
// return something.
}
}
Run Code Online (Sandbox Code Playgroud) 当我尝试从mysql数据库加载一个对象(一行)时,字符串属性未正确加载,因此当我打印它们时,不会显示任何内容.
这是我的hibernate配置文件:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/demo_hib_1
</property>
<property name="connection.username">root</property>
<property name="connection.password"> </property>
<property name="pool_size">5</property>
<property name="show_sql">true</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<!-- Mapping files -->
<mapping resource="com/navid/Person.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)
我尝试将连接url添加到编码中:
jdbc:mysql://localhost:3306/demo_hib_1&characterEncoding=UTF-8
Run Code Online (Sandbox Code Playgroud)
并获得了hibernate异常:
Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2246)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2158)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2137)
at com.navid.Main.main(Main.java:31)
Caused by: org.dom4j.DocumentException: Error on line 10 of document : The reference to entity "characterEncoding" must end with the …Run Code Online (Sandbox Code Playgroud)