可能答案是相当愚蠢但我需要一双新鲜的眼睛来发现问题,如果你愿意的话.这是_tmain的摘录:
Agent theAgent(void);
int m = theAgent.loadSAG();
Run Code Online (Sandbox Code Playgroud)
这是agent.h,我包含在_tmain中:
#ifndef AGENT_H
#define AGENT_H
class Agent {
public:
Agent(void);
int loadSAG(void);
~Agent(void);
};
#endif
Run Code Online (Sandbox Code Playgroud)
和agent.cpp相关的功能:
int Agent::loadSAG(void) {
return 3;
}
Run Code Online (Sandbox Code Playgroud)
那么为什么在世界上我得到这个错误:错误C2228:'.loadSAG'的左边必须有class/struct/union?
提前致谢.
这是代码,是欧拉项目中问题11的解决方案的一部分:
sum_d = 0
j = 0
while j < 20:
i = 0
while i < 20:
try:
sum_d = grid[j][i] * grid[j+1][i+1] * grid[j+2][i+2] * grid[j+3][i+3]
if sum_d > result:
result = sum_d
except IndexError:
pass
i += 1
j += 1
Run Code Online (Sandbox Code Playgroud)
我的问题是,捕获这些异常是否被视为代码气味?我可以看到调试这样的代码会更难(比方说,我意外地循环了19个项而不是20个,它会更难跟踪)但是它比i < (GRID_WIDTH - NUM_ITEMS_IN_PRODUCT)
循环检查中的编码更优雅.
PS我已经解决了问题,我在谈论代码的风格
这是代码:
# a = Array.new(3, Array.new(3))
a = [[nil,nil,nil],[nil,nil,nil]]
a[0][0] = 1
a.each {|line| p line}
Run Code Online (Sandbox Code Playgroud)
随着输出:
[1, nil, nil]
[nil, nil, nil]
Run Code Online (Sandbox Code Playgroud)
但使用注释行:
[1, nil, nil]
[1, nil, nil]
[1, nil, nil]
Run Code Online (Sandbox Code Playgroud)
那为什么呢?
我想从mongoid中使用这个函数:
person.update_attributes(first_name: "Jean", last_name: "Zorg")
Run Code Online (Sandbox Code Playgroud)
但我想从另一个变量传递所有属性.我怎么做?
编辑:谢谢大家的回复.我是红宝石的新手,所以起初我以为我犯了一个愚蠢的错误.错误是在一个完全不同的地方,正确的代码,为您的乐趣:
def twitter
# Scenarios:
# 1. Player is already signed in with his fb account:
# we link the accounts and update the information.
# 2. Player is new: we create the account.
# 3. Player is old: we update the player's information.
# login with a safe write.
puts "twitter"
twitter_details = {
twitter_name: env["omniauth.auth"]['user_info']['name'],
twitter_nick: env["omniauth.auth"]['user_info']['nickname'],
twitter_uid: env["omniauth.auth"]['uid']
}
if player_signed_in?
@player = Player.find(current_player['_id'])
else
@player = Player.first(conditions: {twitter_uid: env['omniauth.auth']['uid']})
end …Run Code Online (Sandbox Code Playgroud) if x < change.pageX # pageX is cross-browser normalized by jQuery
val = Number(elem.text())
return elem.text(o.max) if val + o.step > o.max
return elem.text(o.min) if val + o.step < o.min
elem.text(val + o.step)
else x > change.pageX
# same thing, only - instead of +
Run Code Online (Sandbox Code Playgroud)
(咖啡脚本,但你明白了).我正在寻找一个获取布尔值并将其转换为1(真)或-1(假)的技巧.这样我就能做到val + converted_bool * o.step并保存一个if.
考虑
a = ['1','2','3','4','5']
for(var i = 0; i < a.length; i++) { if (a[i] == 3) console.log('found it!') }
Run Code Online (Sandbox Code Playgroud)
和
a = {'1': true, '2': true, '3': true, '4': true}
a['3']
Run Code Online (Sandbox Code Playgroud)
哪个会更快,为什么?
javascript ×2
jquery ×2
ruby ×2
arrays ×1
c++ ×1
class ×1
code-golf ×1
coffeescript ×1
exception ×1
mongoid ×1
namespaces ×1
node.js ×1
performance ×1
python ×1