So I am trying to implement a Vector class.
I am getting the error "expected type-specifier before '[' token" in my 'at' function, as shown below:
T Vector<T>::at(unsigned i){
return operator[i];
}
I have tried:
return this->operator[i];
and
(*this).operator[i];
but to no avail. Any ideas?
The syntax would be
return this->operator[](i);
or more canonically
return (*this)[i];
Related
I need some help with this query, I don't understand why am I getting this error "Parse error: syntax error, unexpected 'return'(T_RETURN)" even though my previous line was working. I checked on other question similar to this error and see if I have similar mistake but I don't think so, I even double checked to see if I am missing any bracket in my query. Can someone please help me? Thanks a lot.
This part of the code work, "if(count($data)>0){" but when I changed to this it doesn't work anymore " if (hire::where('hire_status','Yes'->count($data) > 0){"
Controller:
public function getHire(){
$data['data'] = DB::table('personal_infos')->where('deleted_at',NULL)->get()->sortByDesc('created_at');
if (hire::where('hire_status','Yes'->count($data) > 0){
// if(count($data)>0){
return view('hire',$data);
}else{
return view('hire');
}
Missing closing parenthesis ).
if (hire::where('hire_status','Yes'->count($data) > 0){
if (hire::where('hire_status', 'Yes')->count($data) > 0) {
Sorry in advance for the large chunk of code. I'm concerned that I may have missed something that is obvious in context.
def remove_runbook_items(runbook_id, runbook_item_id)
item_id = runbook_item_id.to_s
method = 'POST'
url = #the_endpoint
data = {
invokeDetail: {
process: 'remove_runbook_items',
parameters: {
runbook_id: runbook_id,
runbook_items: {
"#{item_id}": {
cores: options[:cores],
ram: options[:ram],
rank: options[:rank],
wait_time: options[:wait_time]
}
}
}
}
}
data.merge! #common_data
result = send_request(method, url, data.to_json)
result['resultDetail'] # Returns contents of response from REST API server
end
The offending line is the one that says "#{item_id}": {
The block of text called "data" is converted into a json, so I must interpolate the string "item_id" or else it will literally spit out "item_id" in the resulting request, rather than item_id's contents. Actually, if there's a way to get at the contents without interpolation, I'd love to know it.
So when I interpolate my string in this way, it works just fine on Ruby 2.3.1. However, when I try to run the same code on a machine using Ruby 1.9.3, I get a litany of syntax errors anywhere I have interpolated a string like this:
/home/mydir/mydir/mydir/mydir/mydir/restapi_helper.rb:1122: syntax error, unexpected ':', expecting tASSOC
"#{device_id}": {
^
/home/mydir/mydir/mydir/mydir/mydir/restapi_helper.rb:1128: syntax error, unexpected '}', expecting keyword_end
/home/mydir/mydir/mydir/mydir/mydir/restapi_helper.rb:1163: syntax error, unexpected ':', expecting tASSOC
"#{item_id}": {
^
/home/mydir/mydir/mydir/mydir/mydir/restapi_helper.rb:1169: syntax error, unexpected '}', expecting keyword_end
/home/mydir/mydir/mydir/mydir/mydir/restapi_helper.rb:1257: syntax error, unexpected ':', expecting tASSOC
"#{item_id}": {
^
/home/mydir/mydir/mydir/mydir/mydir/restapi_helper.rb:1263: syntax error, unexpected '}', expecting keyword_end (SyntaxError)
Does anybody have any advice? Upgrading the version of ruby on the test machines is unfortunately not an option.
It is not iterpolation that is the problem.
{ symbol: value } is a new syntax, which is a shortcut for { :symbol => value }. In its first iteration, I don't think it supported { "symbol": value } automatic string symbolification feature. Use the old-fashioned { "symbol".to_sym => value } if backward compatibility is a goal.
(If you know that all you're doing is converting to JSON, you can even just leave it as { "string" => value }, comforted by the knowledge that JSON does not make a distinction between strings and symbols; but I'd consider it a code smell.)
I am using underscore.js to put my EJS values to template.
I am getting unexpected token if error
When i click on the error i am getting x.for and for each ananymous function.this is code below
enter code here
var a; is and array of objects.
_.each(a,function(b){
var tem=_.template('$('#id1').html());
$('.c').append(tem(p:b));}
any idea what's going wrong?
Trying to pass a block in the method:
self.handler_method("pinterest", do |pinterest|
handle_facebook(pinterest.get_facebook[:username]) if pinterest.facebook_found?
handle_twitter(pinterest.get_twitter[:username]) if pinterest.twitter_found?
end).call(username)
Which keeps returning error:
syntax error, unexpected keyword_do_block (SyntaxError)
self.handler_method "pinterest", do |pinterest|
^
How can I fix it such that it accepts both arguments. I can do the inline block way {} but would rather the expanded with do, end
Thanks
It should be:
self.handler_method("pinterest") do |pinterest|
handle_facebook(pinterest.get_facebook[:username]) if pinterest.facebook_found?
handle_twitter(pinterest.get_twitter[:username]) if pinterest.twitter_found?
end.call(username)
This is the error:
No 'new' for class 'Spec::Benchmark::bzip2401' in 'C:/Users/Tester/Documents/SpecINT2k6_WoT/benchspec/CPU2006/401.bzip2/Spec/object.pm'
point of error in locate.pl file:
my $class="Spec::Benchmark::${name}${num}";
if (!$class->can('new')) {
Log(0, "\nNo 'new' for class '$class' in '$pm'\n");
next;
}
here is the link to the whole locate.pl file http://ks.tier2.hep.manchester.ac.uk/Repositories/other-software/SPEC_CPU2006v1.1/bin/locate.pl
This is the object.pm file http://codepad.org/O196ykIq
I am getting this error while running Specint2006 suite, but this error is not related to the suite. Can anyone tell me what does !$class->can('new') do and why is it returning true here?
Thanks.
Can checks if the Class has the method. The return value is always the coderef. If the class dont know the method, the return value is undef.
The Class dont know the new method, so its false. But you call it with not
!$class->can('new')
Quote from HERE
Again, the same rule about having a valid invocand applies -- use an eval block or blessed if you need to be extra paranoid.