我有以下代码:
java.util.List<String> result = new java.util.LinkedList<>();
Run Code Online (Sandbox Code Playgroud)
并添加了一些字符串。
但我想退货String[]。理想情况下,我想写
return (String[])result.toArray();
但是我在运行时遇到转换错误。(无法转换Object[]为String[])。有没有办法解决这种不涉及手工逐元素复制的问题?
我的编译器(MSVC2012)默认false为最终参数
std::vector<bool>::resize(std::vector<bool>::size_type, bool)
这是标准的C++还是Microsoft扩展?
我不认为对于非专业化而言resize,由于大小增加而引入的任何元素都未初始化.
http://en.cppreference.com/w/cpp/container/vector_bool似乎没有说清楚.
我有一些从数字中提取位的代码:
uint32_t foo = getValue(); /*this just returns a value for `foo`*/
while (foo){
foo <<= 2;
doSomethingWithFoo(foo);
}
Run Code Online (Sandbox Code Playgroud)
我担心我在这里有未定义的行为,因为我最终会 "overshifting" foo。我对么?
我有以下内容enum:
enum enumLoanPaymentPolicy
{
Unspecified = 0,
InterestInArrears = 1 << 1,
InterestInAdvance = 1 << 2,
RoundUpRepayments = 1 << 3,
RoundInterest = 1 << 4,
RoundUpFlows = 1 << 5,
RoundingMask = RoundUpRepayments | RoundInterest | RoundUpFlows,
};
Run Code Online (Sandbox Code Playgroud)
然后在其他地方,给定foo这个枚举的value(),我想提取与之相关的位集Round.
我用foo & RoundingMask它,但我应该使用什么类型?
理想情况下我会使用somethingorother(enumLoanPaymentPolicy) bar = foo & RoundingMask其中somethingorother有点像decltype.这甚至可能吗?
由于我的写作,我没有给出任何理由的代码审查失败,因为一个函数s(String类型)作为参数传递
if (s == null){
s = new String();
}
Run Code Online (Sandbox Code Playgroud)
说我应该用s = "";.为什么?
我有一个foo有田地的课String[] bar.我想foo实施Iterable<String>.
所以我正在写作
@Override
public Iterator<String> iterator() {
// ToDo - return some function of `bar`
}
Run Code Online (Sandbox Code Playgroud)
我可以把什么在标线ToDo做一个Iterator出来bar?
那是什么?在函数声明中表示.
public MyFunction(myParameter ?: number){...}
Run Code Online (Sandbox Code Playgroud) 对于某种int类型n,您如何重铸表达式
(n & 1)
Run Code Online (Sandbox Code Playgroud)
在if语句中使用时用Java编译?在C和C++中编译很好.
我试过的事情:
if (n & 0x1)
if (n & 0x1 == 0x1)
if (n & 0x1 == true)
Run Code Online (Sandbox Code Playgroud)
但是编译器不喜欢这些.
我有一个结构
struct foo : public std::map<std::string, int>
{
};
Run Code Online (Sandbox Code Playgroud)
和儿童结构;
struct bar : public foo
{
int another_member;
}
Run Code Online (Sandbox Code Playgroud)
但我不能使用bar* b = dynamic_cast<bar*>(f)f是指向foo的指针.
即使我重构foo到
struct foo
{
std::map<std::string, int> m;
};
Run Code Online (Sandbox Code Playgroud)
我还有问题.我玩过我的RTTI设置无济于事.到底是怎么回事?
错误是:
错误C2683:'dynamic_cast':'Credit :: WaterfallSimulationResult'不是多态类型
我有这行代码:
out = std::min(x - 1, y - 1);
Run Code Online (Sandbox Code Playgroud)
但它返回了两个量中较大的一个.怎么会这样?
c++ ×4
java ×4
arrays ×1
c ×1
collections ×1
dynamic-cast ×1
javascript ×1
typescript ×1
vector ×1
visual-c++ ×1