我有一个看起来像这样的函数:
bool generate_script (bool net, bool tv, bool phone,
std::string clientsID,
std::string password,
int index, std::string number,
std::string Iport, std::string sernoID,
std::string VoiP_number, std::string VoiP_pass,
std::string target, int slot, int port,
int onu, int extra, std::string IP, std::string MAC);
Run Code Online (Sandbox Code Playgroud)
在我看来,它看起来很难看.处理这个问题的正确方法是什么?我应该创建几个具有不同数据类型(int,string和bool)的向量,并将它们作为参数传递给此函数吗?
#include <memory>
class bar{};
void foo(bar &object){
std::unique_ptr<bar> pointer = &object;
}
Run Code Online (Sandbox Code Playgroud)
我想将对象的地址分配给指针.上面的代码显然不会编译,因为赋值运算符的右侧需要是std :: unique_ptr.我已经尝试过了:
pointer = std::make_unique<bar>(object)
Run Code Online (Sandbox Code Playgroud)
但它在编译过程中会抛出许多错误.我怎样才能做到这一点?
更新
如答案中所述 - 使用该std::unique_ptr::reset方法导致未定义的行为.现在我知道,在这种情况下我应该使用标准指针.
我需要使用SOAP从数据库中检索一些数据.我不是一个经验丰富的PHP程序员,这就是我需要一些帮助的原因.提供webservice(WSDL)的公司给了我登录信息和svc和wsdl文件的链接.他们还给了我一个如何连接C#的例子:
var proxy = new ChannelFactory<ServiceReferenceWCF.IWebService2>("custom");
proxy.Credentials.UserName.UserName = login;
proxy.Credentials.UserName.Password = pass;
var result = proxy.CreateChannel();
var logged_in = result.loggedIn();
Run Code Online (Sandbox Code Playgroud)
这是我的PHP代码:
$wsdl_proto = 'https';
$wsdl_host = 'their_wsdl_host';
$wsdl_host_path = 'their_wsdl_path';
$namespace_proto = 'https';
$namespace_host = 'their_namespace_host';
$namespace_path = 'their_namespace_path';
$location = $namespace_proto.'://'.$namespace_host.$namespace_path;
$wsdl_url = $wsdl_proto.'://'.$wsdl_host.$wsdl_host_path;
$connection = new SoapClient($wsdl_url, array('location' => $location, 'soap_version' => SOAP_1_1, 'connection_timeout'=> 600,
'proxy_login' => "my_login", 'proxy_password' => "my_password"));
$functions = $connection->__getFunctions();
var_dump($functions);
$logged_in = $connection->loggedIn();
Run Code Online (Sandbox Code Playgroud)
它在loggedIn()函数调用期间挂起.此函数列在$ functions变量中,因此它是有效的.我尝试了服务提供的其他一些功能 - 结果总是一样的:脚本只是冻结了.我的意思是服务没有响应,PHP等待loggedIn()功能完成.超过超时后,我收到一个错误:Error Fetching …
这是一个例子(不起作用):
type
menu = class
private
menu_element = RECORD
id: PtrUInt;
desc: string;
end;
public
procedure foo();
end;
Run Code Online (Sandbox Code Playgroud) 我正在尝试做这样的事情:
#include <thread>
#include <vector>
void foo(bool &check){
}
int main(){
std::vector<bool> vec(1);
std::thread T(foo, std::ref(vec[0]));
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,gcc抛出一个错误:
prog.cpp: In function 'int main()':
prog.cpp:10:34: error: use of deleted function 'void std::ref(const _Tp&&) [with _Tp = std::_Bit_reference]'
std::thread(foo, std::ref(vec[1]))
^
In file included from /usr/include/c++/4.9/thread:39:0,
from prog.cpp:1:
/usr/include/c++/4.9/functional:453:10: note: declared here
void ref(const _Tp&&) = delete;
Run Code Online (Sandbox Code Playgroud)
但它适用于普通变量:
bool var;
std::thread(foo, std::ref(var));
Run Code Online (Sandbox Code Playgroud)
我不知道为什么我不能传递对vec元素的引用.有人可以解释原因吗?有没有解决方法?
我知道如何嵌入具有特定ID的Feed.我已经做到了.现在,我想实现以下功能:如果用户收到私人消息,它将显示在嵌入式Feed中.我认为最好的选择是嵌入整个"聊天窗口",但我没有在网上找到单个代码示例.我怎样才能做到这一点?
我正在寻找一个如何使用初始化列表的简单示例.这就是我想要做的:我有以下课程:
class foo{
public:
void set_x(const int ix);
void set_y(const int iy);
void display();
private:
int x;
int y;
};
Run Code Online (Sandbox Code Playgroud)
我想以下列方式创建此类的对象:
foo fooObj = {1, 2};
Run Code Online (Sandbox Code Playgroud)
我知道在C++ 11中使用vector是可能的.我该如何实现这种行为?
我需要编写一个计算数学公式的简单程序.这里唯一的问题是其中一个变量的值可以是10 ^ 100.因此,我不能用C++/C编写这个程序(我不能使用像gmp这样的外部库).几个小时前我读到Python能够计算这些值.我的问题是:为什么
print("%.10f"%(10.25**100))
Run Code Online (Sandbox Code Playgroud)
正在返回这个号码 "118137163510621843218803309161687290343217035128100169109374848108012122824436799009169146127891562496.0000000000"
而不是
"118137163510621850716311252946961817841741635398513936935237985161753371506358048089333490072379307296.453937046171461"?
看看以下示例:
#!/bin/bash
test(){
return 1;
}
VAR=$(expect -c 'puts "Exiting"; exit 1;');
echo "$VAR";
RETURN_CODE=$?;
echo $RETURN_CODE;
test
RETURN_CODE=$?;
echo $RETURN_CODE;
Run Code Online (Sandbox Code Playgroud)
该脚本的输出将是:
Exiting
0
1
Run Code Online (Sandbox Code Playgroud)
我的猜测是,第一个0是"echo"的返回码.我对吗?如果是这样,那么如何捕获expect命令的返回码?
我不知道这个主题是否与std :: thread库或流有关.看看下面的例子:
#include <thread>
#include <iostream>
void read(){
int bar;
std::cout << "Enter an int: ";
std::cin >> bar;
}
void print(){
std::cout << "foo";
}
int main(){
std::thread rT(read);
std::thread pT(print);
rT.join();
pT.join();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我不在乎它是否会在执行read()函数之前或之后打印"foo"字符串.困扰我的是,当它在执行print()函数之前要求输入时,它实际上会挂起执行.我必须单击"输入"或用一些数据提供std :: cin才能看到"foo"字符串.下面您可以看到该程序行为的三种可能方案:
1.
>> Enter an int: //here I've clicked enter
>> foo
>> 12 //here I've written "12" and clicked enter
//end of execution
2.
>> fooEnter an int: 12 //here I've written "12" and clicked enter
//end of execution …Run Code Online (Sandbox Code Playgroud) 我的C++项目变得越来越大.在某些情况下,我只是为了自己的方便而通过引用传递参数,有些我不这样做.这是一个例子:
struct foo{
foo(int &member){
this->member = &member;
}
private:
int *member;
};
Run Code Online (Sandbox Code Playgroud)
当我不想创建int变量的两个实例时,我正在使用此模式.我没有必要实现get或modify方法来操纵它的值.相反,我甚至可以在不访问foo对象的情况下更改变量.但有时我使用不同的方式管理成员变量:
struct foo{
foo(int member){
this->member = member;
}
void modify_member(){
this->member = 6;
}
int get_member(){
return this->member;
}
private:
int member;
};
Run Code Online (Sandbox Code Playgroud)
我不确定在同一结构中混合使用这两种管理成员的方法是一种很好的做法.我应该将其正常化吗?那么例如给定结构中的每个函数都将使用"按值传递"方法?
最近我遇到了以下部分代码.我不知道它是否有任何意义,我只是想了解它:
#include <iostream>
class foo{
private:
int memeber;
public:
int &method(){ return memeber; }
};
int main(){
foo bar;
std::cin >> bar.method();
}
Run Code Online (Sandbox Code Playgroud)
我以前从未见过这样的事.我很惊讶它甚至编译.你怎么能直接找到一个函数地址?有人可以详细说明它的作用以及它是否可以用于任何事情?
c++ ×7
c++11 ×3
bash ×1
c++14 ×1
delphi ×1
embed ×1
expect ×1
function ×1
inputstream ×1
javascript ×1
numbers ×1
outputstream ×1
pascal ×1
php ×1
python ×1
reference ×1
return-value ×1
soap ×1
soap-client ×1
types ×1
unique-ptr ×1
vector ×1
wsdl ×1
yammer ×1