在VS 10中,我收到警告:
warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
Run Code Online (Sandbox Code Playgroud)
试图编译
int x ;
static_cast<bool>(x);
Run Code Online (Sandbox Code Playgroud)
如何编写一个不会引起此警告的代码?
我有几个类,每个类使用相同的,enum
但根据其要求扩展了一点.例如 :
class skirtColor{
enum Color{
red = 1,
blue = 10,
green = 12
};
};
class dressColor {
enum Color{
red = 1,
pink,
yellow,
blue = 10,
green = 12
};
};
class pantsColor {
enum Color {
red = 1,
brown,
blue = 10,
green = 12
};
};
Run Code Online (Sandbox Code Playgroud)
由于C++中没有枚举的继承,我想define
用于一个共同的部分
#define COLOR\
// red color \
red = 1,\
// blue color \
blue = 10,\
//green color
green = 12,
Run Code Online (Sandbox Code Playgroud)
之后,我可以在类中重用常见的颜色定义 …
我有以下代码:
std::map<size_t,Cell&> m_cellMap;
Run Code Online (Sandbox Code Playgroud)
当Cell定义如下:
class Cell
{
public:
Cell(int x = 0,int y = 0) : m_x(x),m_y(y) { }
private:
int m_x;
int m_y;
/// class members and methods
};
Run Code Online (Sandbox Code Playgroud)
我不能编译下面的代码:
Cell c;
m_cellMap[0] = c;
Run Code Online (Sandbox Code Playgroud)
得到错误:出了error C2101: '&' on constant
什么问题?如何解决?
谢谢
我有一个带参数@id int OUTPUT
的存储过程(sql server 2012)该过程向数据库表中插入一些数据并返回受影响行的ID
SET @id=SCOPE_IDENTITY()
RETURN @id
Run Code Online (Sandbox Code Playgroud)
我从SQL Server测试它,它工作正常.但是当我从C#调用它时:它确实将数据插入到表中,但返回null:
SqlParameter parm = new SqlParameter("@id", SqlDbType.Int);
parm.Size = 32;
parm.Direction = ParameterDirection.Output; // This is important!
cmd.Parameters.Add(parm);
object id = (int?)cmd.ExecuteScalar();//<-null
Run Code Online (Sandbox Code Playgroud)
请指出导致这种奇怪行为的原因是什么?
我有DateTimeOffset输入参数.需要创建其他DateTimeOffset参数,其中月份比输入少2个月:
//DateTimeOffset input;
DateTimeOffset modified = new DateTimeOffset(input.Year,
input.Month - 2, input.Day,
input.Hour, input.Minute,
input.Second, input.Millisecond,
input.Offset);
I get an exception
Run Code Online (Sandbox Code Playgroud)
年,月和日参数描述不可表示的DateTime.
怎么了? - 月份是4. S0 4-2 = 2有效谢谢
我有按第二列排序的表 (1000000x4) 的 Spark 数据框 我需要获取第二行第 0 列和第二行第 3 列的 2 个值 我该怎么做?
根据此https://docs.cloudant.com/document.html#bulk-operations 我试图将多个文档插入我的 cloudant 数据库,但出现错误:
{
"error": {
"statusCode": 400,
"name": "Error",
"request": {
"method": "POST",
"headers": {
"content-type": "application/json",
"accept": "application/json"
},
"uri": "https://XXXXXX:XXXXXX@8f7fc7f0-766b-4429-b060-4ef1c01f7665-bluemix.cloudant.com/ttt/_bulk_docs",
"body": "[{\"name\":\"Nicholas\",\"_id\":\"96f898f0-f6ff-4a9b-aac4-503992f31b01\",\"_attachments\":{},\"age\":45,\"gender\":\"male\"},{\"name\":\"Taylor\",\"_id\":\"5a049246-179f-42ad-87ac-8f080426c17c\",\"_attachments\":{},\"age\":50,\"gender\":\"male\"},{\"name\":\"Owen\",\"_id\":\"d1f61e66-7708-4da6-aa05-7cbc33b44b7e\",\"_attachments\":{},\"age\":51,\"gender\":\"male\"}]"
},
"description": "couch returned 400",
"scope": "couch",
"reason": "Request body must be a JSON object",
"error": "bad_request",
"stack": "Error: Request body must be a JSON object\n at Request._callback (/nodejsAction/node_modules/cloudant-nano/lib/nano.js:247:15)\n at Request.self.callback (/nodejsAction/node_modules/request/request.js:186:22)\n at emitTwo (events.js:106:13)\n at Request.emit (events.js:191:7)\n at Request.<anonymous> (/nodejsAction/node_modules/request/request.js:1081:10)\n at emitOne (events.js:96:13)\n at Request.emit (events.js:188:7)\n at IncomingMessage.<anonymous> (/nodejsAction/node_modules/request/request.js:1001:12)\n at IncomingMessage.g (events.js:291:16)", …
Run Code Online (Sandbox Code Playgroud) 我有以下.h文件
class Node
{
private :
int m_data;
Node* m_left;
Node* m_right;
public:
Node(int data) : m_data(data), m_left(nullptr), m_right(nullptr) {}
Node* getLeft() { return m_left; }
Node* getRight() { return m_right; }
int getData() { return m_data; }
};
class Tree
{
private :
Node * m_root;
unsigned int m_size;
void freeNode(Node*);
bool insert(Node**, int );
public:
Tree() : m_size(0) {}
~Tree();
int findMaximumVericalSum();
bool insert(int);
};
Run Code Online (Sandbox Code Playgroud)
实施时,出现错误-什么地方出了问题以及如何解决
'&'需要l值
地址运算符(&)必须具有一个l值作为操作数。
bool Tree::insert(Node** root, int data)
{
Node* newNode = new …
Run Code Online (Sandbox Code Playgroud) 我想创建一个字符串模板,其内容的一部分最近将完成
string myTemplete = "This is a template ,which depends on {1} and {2} and {3}"
Run Code Online (Sandbox Code Playgroud)
之后我有一些函数调用链,我从中收集数据
int arg1 = MyFunc1();
string arg2 = MyFunc2();
string arg3 = MyFunc3();
Run Code Online (Sandbox Code Playgroud)
//需要使用arg 1
for {0}
,arg2 for {1}
,arg3
for 填充myTemplete{2}
我该怎么做?我构建的模板很长,并且在许多地方使用,因此不想制作类似的东西
int arg1 = MyFunc1();
string arg2 = MyFunc2();
string arg3 = MyFunc3();
string myData = string.Format("This is a template ,which depends on {1} and {2} and {3}"
,arg1, arg2, arg3);
Run Code Online (Sandbox Code Playgroud) 我在 cs 文件中有以下代码(在 Visual Srudio 中编译)
#if __cplusplus
// C++ region, hide the private C# key word "private" from C++
#define private
namespace fastmapping
{
#else
// C# region, namespace and class so the C++ enum would not be the same in C#
namespace Interface
{
public static class Example
{
#endif
// Common part to both C# and C++ (in C++ the private keyword is omitted by define)
private enum GatedMode
{
GATED_MODE,
NON_GATED_MODE
};
// other enums
} …
Run Code Online (Sandbox Code Playgroud) 我有IP地址的字符串string ip = "123.37.71.238,123.37.71.239"
(这是一个例子,实际上它有大约100个地址),需要生成这串名单
我该怎么做?谢谢
问题基于以下类层次结构.
Base2* d3 = new Der3();
d3->v1();
delete d3;
Run Code Online (Sandbox Code Playgroud)
输出是:
Base1
Base1
Der1
Base2
Der3
v1 Base2
~Base2
Run Code Online (Sandbox Code Playgroud)
我得到一个例外.为什么?(它只会产生内存泄漏)
class Base1
{
public:
Base1() {std::cout << "Base1" << std::endl; }
~Base1() {std::cout << "~Base1" << std::endl; }
virtual void v1() { std::cout << "v1 Base1" << std::endl; }
void v2() {std::cout << "v2 Base1" << std::endl;}
void v3() {std::cout << "v3 Base1" << std::endl;}
};
class Base2
{
public:
Base2() {std::cout << "Base2" << std::endl; }
~Base2() {std::cout << "~Base2" …
Run Code Online (Sandbox Code Playgroud) c++ ×6
c# ×5
apache-spark ×1
assign ×1
boolean ×1
casting ×1
cloudant ×1
couchdb ×1
couchdb-nano ×1
dataframe ×1
enums ×1
ibm-cloud ×1
int ×1
ip-address ×1
json ×1
list ×1
macros ×1
map ×1
pointers ×1
reference ×1
return-value ×1
sql ×1
sql-server ×1
string ×1
warnings ×1