我想为一个类赋一个声明值,所以我做了这个基本类:
String sql = "INSERT INTO TEMP (Table_Id, STATUS, VERSION,Name) " +
"VALUES (?, ?, SELECT (VERSION+1) FROM (SELECT VERSION, Table_Id, MAX(VERSION) OVER(PARTITION BY Table_Id) MAX_V FROM TEMP ) WHERE Table_Id = ? AND VERSION = MAX_V, ?)";
getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i){
try {
TDetails customer = chngCustStus.get(i);
ps.setInt(1, customer.getTableId());
ps.setInt(1, customer.getStatus());
ps.setInt(1, customer.getTableId());
ps.setInt(1, customer.getName());
} catch (SQLException e) {
//TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public int getBatchSize() {
return chngCustStus.size();
}
用这个主要编译它:
m = df['conlumn_a'] == 'apple'
df.loc[m,'conlumn_b'] = df.loc[m,'conlumn_b'].astype(str).replace(r'^(11+)','XXX',regex=True)
print (df)
conlumn_a conlumn_b
0 apple 123
1 banana 11
2 apple XXX
3 orange 33
但编译器抱怨此错误消息:
class A
{
public:
A &operator=(int)
{
return (*this);
}
};
但是当我用这个主编译时:
int main(void)
{
A x = 1;
}
一切顺利编译
为什么我的第一个主程序不能编译,如何更改类A以便编译?
答案 0 :(得分:7)
A x = 1;
是初始化,而不是赋值;他们是不同的东西。它不会调用赋值运算符,但需要converting constructor。
class A
{
public:
// converting constructor
A (int) {}
A &operator=(int)
{
return (*this);
}
};
然后
A x = 1; // initialize x via converting constructor
x = 2; // assign x via assignment operator