scope

Should a typedef be both in the class definition and class declaration?

蹲街弑〆低调 提交于 2020-01-30 07:00:05
问题 I'm learning C++. I know that C++ is a bit more verbose than most other languages, however defining a typedef in a struct/ class declaration and then again in the struct/ class definition got me thinking if there isn't a better or more central place for the typedef where it only has to be defined once, and whether this follows what is thought of as C++ best practices. I couldn't find anything in particular about this on the web. Moving the typedef to a more global place seems inappropriate

PHP error with variable in callback function

北慕城南 提交于 2020-01-30 06:41:06
问题 I have this function in php (laravel): public static function isUserParticipatesInTournament($tourId, $userId) { var_dump($userId); //dumped $user = User::find($userId); if(!$user) { return null; } $obj = $user->whereHas('tournaments', function($query) { var_dump($tourId); //error $query->where('id', '=', $tourId); //error })->get(); return $obj; } The problem is that in the closure $obj = $user->whereHas('tournaments', function($query){...} the $tourId variable is undefined in it. I am

Why can't the VBA Me keyword access private procedures in its own module?

痞子三分冷 提交于 2020-01-28 10:28:25
问题 I just discovered that the Me keyword cannot access private procedures even when they are inside its own class model. Take the following code in Class1: Private Sub Message() Debug.Print "Some private procedure." End Sub Public Sub DoSomething() Me.Message End Sub This code instantiates an instance of the class: Sub TestClass() Dim objClass As New Class1 objClass.DoSomething End Sub Me.Message throws compile error "Method or data member not found." If I change Private Sub Message() to Public

JS: revealing module pattern - accessing internal objects vs arrays?

自闭症网瘾萝莉.ら 提交于 2020-01-25 12:24:05
问题 Using the revealing module pattern, how can I provide direct access to non-static private variables? Here's what I have: var M = function () { var obj = {}; var arr = []; var change = function () { obj = {"key":"if I see this, O is a reference to obj"}; arr.push("If I see this, A is a reference to arr") }; return { change: change, O: obj, A: arr }; }(); M.change(); console.log(M.A); // prints ["If I see this, A is a reference to arr"] console.log(M.O); // prints Object {}, wanted "if I see

Search scope for multiple columns of data in Laravel Model

泄露秘密 提交于 2020-01-25 10:31:08
问题 I have a Model within Laravel called Blah (I named it this way because you can't simply name a class Class , so I changed the name temporarily). Within the classes table, each row contains data like this: { year: "2015", term: "Summer", subject_code: "DIGM", course_no: "350", instr_type: "Lecture", instr_method: "Face To Face", section: "003", crn: "42953", course_title: "Digital Storytelling", credits: "3.0", day: "R", time: "06:30 pm - 09:20 pm", instructor: "Teacher Name", campus:

Search scope for multiple columns of data in Laravel Model

本秂侑毒 提交于 2020-01-25 10:31:06
问题 I have a Model within Laravel called Blah (I named it this way because you can't simply name a class Class , so I changed the name temporarily). Within the classes table, each row contains data like this: { year: "2015", term: "Summer", subject_code: "DIGM", course_no: "350", instr_type: "Lecture", instr_method: "Face To Face", section: "003", crn: "42953", course_title: "Digital Storytelling", credits: "3.0", day: "R", time: "06:30 pm - 09:20 pm", instructor: "Teacher Name", campus:

jQuery.post() scope issue while trying to overwrite global variable [duplicate]

余生颓废 提交于 2020-01-25 06:32:10
问题 This question already has answers here : How do I return the response from an asynchronous call? (37 answers) Closed 5 years ago . I'm facing some difficulties in my code related to scope. Here is my code: <script type="text/javascript"> var totalHoras = {}; var dadosCategorias = {"teste": "1234"}; var t; // timeout handler para exibição de feedback para o usuário $().ready(function() { // obtém dados das categorias var obterDadosCategorias = function() { $.post( "{{ baseRoute }}/cadastro

Access local variable from outside the function

情到浓时终转凉″ 提交于 2020-01-25 05:21:05
问题 I'm using TopUp to make a simple slideshow. Unfortunately they don't expose the image index. Is there a way I can access the local variable "index" without having to modify the original script? TopUp = (function() { var index = null; ... } 回答1: Without modifying the original script, you can't. But if you just want to be able to read the value of index , the modification could be really simple, by adding a little function in the objet returned : getIndex : function() { return index; }, 回答2:

Find tags with articles

强颜欢笑 提交于 2020-01-24 23:34:25
问题 On blog app I want to display list of tags with articles. class Article < AR::B has_and_belongs_to_many :tags end class Tag < AR::B has_and_belongs_to_many :articles end What would Tag scope look like? Tag.joins(:articles) ... # should return tags associated to at least 1 article 回答1: One way to do this with Ruby/Rails would be this one. Tag.includes(:articles).select { |tag| tag.articles.any? } .includes makes sure that the articles are loaded alongside the tags, which is more efficient than

Why should I declare implemented interface methods as “public”?

…衆ロ難τιáo~ 提交于 2020-01-24 20:46:05
问题 interface Rideable { String getGait(); } public class Camel implements Rideable { int weight = 2; String getGait() { return " mph, lope"; } void go(int speed) {++speed; weight++; int walkrate = speed * weight; System.out.print(walkrate + getGait()); } public static void main(String[] args) { new Camel().go(8); } } Upon compiling the above code I've got a compilation error, related to access modifier of getGait() method. Please explain, why should I declare getGait() with public access