花了最后几天尝试使用C++ operator []方法,我遇到了一个我无法解释的异常现象.下面的代码实现了一个简单的测试字符串类,它允许用户通过其下标"operator"方法访问单个字符.由于我想区分左值和右值下标上下文,"operator"方法返回自定义"CReference"类的实例,而不是标准的C++字符引用.虽然"CReference""operator char()"和"operator =(char)"方法似乎分别处理每个rvalue和lvalue上下文,但g ++拒绝编译而没有记录的附加"operator =(CReference&)"方法下面.虽然添加此方法似乎安抚了某种编译时依赖性,但在程序执行期间从未在运行时实际调用它.
作为一个认为自己已经对C++复杂性有了基本了解的人,这个项目无疑已经证明是一种令人羞愧的体验.如果有人能够看到他们的方式来启发我在这里发生了什么,我会永远感激.与此同时,我将不得不拔出C++书籍,以便在我所知道的和我认为知道的东西之间调和.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
// Class for holding a reference to type char, retuned by the "operator[](int)"
// method of class "TestString". Independent methods permit differentiation
// between lvalue and rvalue contexts.
class CReference
{
private:
char& m_characterReference;
public:
// Construct CReference from char&
CReference(char& m_initialiser)
: m_characterReference(m_initialiser) {}
// Invoked when object is referenced in a rvalue char context.
operator char()
{
return m_characterReference;
}
// Invoked when object …Run Code Online (Sandbox Code Playgroud) 我有下一个xml:
<page>
<document>
<id>1001</id>
<cur>USD</cur>
<date>01.01.2009</date>
<amount>10</amount>
</document>
<document>
<id>1001</id>
<cur>USD</cur>
<date>02.01.2009</date>
<amount>15</amount>
</document>
<document>
<id>1001</id>
<cur>JPY</cur>
<date>01.01.2009</date>
<amount>5</amount>
</document>
<document>
<id>1002</id>
<cur>USD</cur>
<date>01.01.2009</date>
<amount>5</amount>
</document>
...
</page>
Run Code Online (Sandbox Code Playgroud)
我需要将其转换为html.记录应按id和cur分组.并且应在每组之后显示总量.所以我们想要这样的东西:
Bill: id=1001, cur=USD
date=01.01.2009 amount=10
date=02.01.2009 amount=15
total amount=25
Bill: id=1001, cur=JPY
date=01.01.2009 amount=5
total amount=5
Bill: id=1002, cur=USD
date=01.01.2009 amount=5
total amount=5
...
Run Code Online (Sandbox Code Playgroud)
如何使用XSL实现这一目标?
当我试图在谷歌找到答案时,我发现了Muenchian方法,但是当我们想要将结果分组为2个字段时,它太复杂了.我是xsl的初学者,这对我来说有点困难.我还为每个组找到了xslt 2.0运算符.主流浏览器是否支持?通常是使用它还是我们应该只依赖xslt 1.0?
我正在SQLServer 2008中创建一个新的架构。
我应该创建一个与架构所有者同名的新用户吗?
我应该使用“ dbo”用户作为架构所有者吗?
我正在Comparable一个包含单个int成员的普通类上实现接口.
我可以这样实现它:
@Override
public int compareTo ( final MyType o )
{
return
Integer.valueOf( this.intVal ).compareTo(
Integer.valueOf( o.intVal )
);
}
Run Code Online (Sandbox Code Playgroud)
但是这(可能)会创建2个完全不必要的Integer对象.
或者我可以从Integer类中尝试一下真正的剪切和粘贴方法:
@Override
public int compareTo ( final MyType o )
{
int thisVal = this.intValue;
int anotherVal = o.intValue;
return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1));
}
Run Code Online (Sandbox Code Playgroud)
这非常有效,但不需要复制代码.
是否有一个库可以实现这个缺失Integer(和Double和Float)方法?
public static int compare ( int v1, int v2 );
Run Code Online (Sandbox Code Playgroud) 我一直在寻找一个脚本,让我在当前系统变量路径的末尾添加文本.有什么建议我怎么能这样做?(特别是,将"; C:\ Program Files(x86)\ Java\jre7\bin\java.exe"添加到现有文本中)
如果我的存储过程中有一个print语句:
print 'message'
Run Code Online (Sandbox Code Playgroud)
有没有办法在通过JDBC连接到SQL Server 2008的java程序中获取输出?
此外,print从JDBC应用程序调用时,是否存在调试消息将关闭连接的危险?
我导入了完整的包名/ java文件,如果我这样做<classname>.<method>,有时我可以访问它 - 有时候我会得到很多can't use a static in a non static话题.
我承认我是Java的新手,所以我需要做什么?先调用一个类实例,然后调用我的方法?我对此感到困惑,因为我想将所有'函数'放入一个FunctionsList.java文件中,并将所有主要的Activity(UI)放入MyActivity.java文件中.
例如:
<MyActivity.java>
import com.example.FunctionsList;
private class MyActivity extends Activity {
FunctionsList.function();
}
Run Code Online (Sandbox Code Playgroud)
9/10次我得到静态/非静态错误.
如果我将所有函数都放入MyActivity.java中,我就没有问题!任何人都可以帮助我,我认为这是一个基本的Java新手问题?
我正在浏览我们的代码库并看到很多像这样的测试:
declare @row_id int = ...
declare @row_attribute string
select
@row_attribute = ROW_ATTRIBUTE
from
SOME_TABLE
where
ROW_ID = @row_id
if @row_attribute is null
begin
... handle not existing condition
end
Run Code Online (Sandbox Code Playgroud)
这是问题,是否可以将if语句中的条件替换为:
if @@rowcount = 0
begin
... handle not existing condition
end
Run Code Online (Sandbox Code Playgroud)
我知道exist函数,但这里的目标是获取行的一些属性并同时检查它的存在.
我试图在Java中测试套接字连接,但失败了.这是我的代码(两个简单的应用程序,服务器和客户端):
public class TestServer {
public static void main(String args[]) throws IOException {
ServerSocket serverSocket = new ServerSocket(1111);
System.out.println("Server socket created");
Socket socket = serverSocket.accept();
System.out.println("Socket accepted");
PrintWriter output = new PrintWriter(socket.getOutputStream(), true);
System.out.println("Output created");
output.write("Output string");
socket.close();
serverSocket.close();
}
}
public class TestClient {
public static void main(String args[]) throws IOException {
Socket socket = new Socket("127.0.0.1", 1111);
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
System.out.println("Input: " + input.readLine());
socket.close();
}
}
Run Code Online (Sandbox Code Playgroud)
输出是(在运行服务器之后,在它之后,客户端):
Server socket created
Socket accepted
Output created …Run Code Online (Sandbox Code Playgroud) 此代码具有某种简单的语法错误.我已经打了好几个小时了,我放弃了.你能发现它吗?我打赌这很容易.谢谢!
当我更新John的第一个名字时,没问题.当我尝试更新姓氏的注释行时,语法错误.
import java.sql.*;
public class UpdateTester {
public static void main(String[] args) {
try {
Connect connect = new Connect();
Connection connection = connect.getConnection();
try {
String sql = "UPDATE student SET firstName = ? "
+ " WHERE studentID = 456987";
//String sql = "UPDATE student SET firstName = ? "
// + " Set lastName = ?, "
// + " WHERE studentID = 456987";
PreparedStatement pst = connection.prepareStatement(sql);
pst.setString(1, "John");
//pst.setString(2, "Johnson");
pst.executeUpdate();
System.out.println("Updated Successfully!");
connection.close(); …Run Code Online (Sandbox Code Playgroud) 我该如何更改此实现:
public interface Animal()
{
public void eat();
}
public class Dog implements Animal
{
public void eat()
{}
}
public void main()
{
// Animal can be instantiated like this:
Animal dog = new Dog();
// But I dont want the user to create an instance like this, how can I prevent this declaration?
Dog anotherDog = new Dog();
}
Run Code Online (Sandbox Code Playgroud) 如果macrodef属性设置为prod,我试图删除以log开头的所有行(例如下面的例子).我打算使用replaceregexp删除以log开头的所有行.但是,除了使用if任务之外,我不确定如何测试属性是否设置为特定值.我想不介绍任何非核心Ant任务来执行此操作,但我无法提出任何其他解决方案.除了使用if-task之外,我还有其他选择吗?
谢谢
<macrodef name="setBuildstamp">
<attribute name="platform" />
<sequential>
<if>
<equals arg1="platform" arg2="prod" />
<then>
<replaceregexp match="^log\(.*" value="" />
</then>
</if>
</sequential>
</macrodef>
Run Code Online (Sandbox Code Playgroud) java ×6
sql-server ×3
android ×1
ant ×1
ant-contrib ×1
batch-file ×1
c++ ×1
compareto ×1
group-by ×1
jdbc ×1
mysql ×1
networking ×1
path ×1
sockets ×1
sql ×1
sql-update ×1
syntax-error ×1
uml ×1
windows ×1
xml ×1
xslt ×1