小编sca*_*ace的帖子

为什么有些类方法返回"*this"(self的对象引用)?

在互联网上有很多代码可以解释(特别是在这里,在stackoverflow上)*this.

例如,来自复制构造函数和C++中的=运算符重载:可能是一个常见的函数吗?:

MyClass& MyClass::operator=(const MyClass& other)
{
    MyClass tmp(other);
    swap(tmp);
    return *this;
}
Run Code Online (Sandbox Code Playgroud)

当我把swap写为:

void MyClass::swap( MyClass &tmp )
{
  // some code modifying *this i.e. copying some array of tmp into array of *this
}
Run Code Online (Sandbox Code Playgroud)

是不是足够设定返回值operator =,以void避免回国*this

c++ this return-value

6
推荐指数
2
解决办法
1227
查看次数

java.net如何触发HTTP请求

我使用java.net在我的Java客户端发送HTTP请求,但我仍然无法实现/找到如何实际触发请求.

例如,我有这个代码:

Scanner sc = new Scanner(System.in);

System.out.println("Deleting subject...");
System.out.println("Subject shortcut (-1 for return):");
String shortcut = sc.next();
if( shortcut.equals("-1") )
    return ;

try
{
    URL url = new URL( "http://localhost:8080/Server/webresources/subject/delete/"+shortcut );
    HttpURLConnection con = (HttpURLConnection)url.openConnection();
    con.setDoOutput(true);
    con.setRequestMethod("DELETE");

    BufferedReader br = new BufferedReader( new InputStreamReader( con.getInputStream() ) );
    System.out.println( br.readLine() );
}catch( Exception e )
{
    System.out.println(e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)

在这段代码中,如果我不使用这些行:

BufferedReader br = new BufferedReader( new InputStreamReader( con.getInputStream() ) );
System.out.println( br.readLine() );
Run Code Online (Sandbox Code Playgroud)

请求永远不会发送.因此,在这种情况下,请求似乎是通过从连接调用InputStream来触发的.

任何人都可以解释我如何通过java.net触发HTTP请求?

java httprequest

4
推荐指数
1
解决办法
905
查看次数

我如何知道在Linux上编写的C程序是否可以在其他地方使用

我需要你解释一下我如何知道我的C程序是否可以在Windows上运行,如果我在Linux上编写它并且它在Linux上工作,反之亦然(用Windows编写的程序)

还有什么标准可以编写将在不同操作系统上运行的程序?如何检测库或整个库中的函数是否可以在不同的操作系统上运行?

比如我有功能fread,fwrite,fopen,fclose从图书馆stdio.h-我怎么知道,如果我能与他们正常的其它系统比Linux工作?同样的,与文件描述符工作职能:open,creat,close,read,write从图书馆:sys/types.h,sys/stat.h,fcntl.h.

c linux windows operating-system

3
推荐指数
1
解决办法
136
查看次数

省略号-传入或传出其他方法的其他参数

我了解点对点通常是什么意思。我想在要使用未知数量的参数创建自己的函数时了解如何使用它。

我不了解它如何工作,例如在function上variable.names()。当我执行时?variable.names,将编写以下内容:

...传入或传出其他方法的其他参数。

到底是什么意思 我不知道我可以通过那里。这些传递的参数将如何以及在何处使用。

r ellipsis

2
推荐指数
1
解决办法
285
查看次数

标签 统计

c ×1

c++ ×1

ellipsis ×1

httprequest ×1

java ×1

linux ×1

operating-system ×1

r ×1

return-value ×1

this ×1

windows ×1