methods

Calling renderRows() on Angular Material Table

允我心安 提交于 2019-12-08 23:37:25
问题 I'm trying to get my Angular Table to refresh after updating the data used in the table. The docs say "you can trigger an update to the table's rendered rows by calling its renderRows() method." but it is not like a normal child component where I can use something "@ViewChild(MatSort) sort: MatSort;" since I do not import it. If I do import it and try something like @ViewChild('myTable') myTable: MatTableModule; then I get an error that says that renderRows() does not exist on that type. How

What are callback methods?

*爱你&永不变心* 提交于 2019-12-08 22:51:13
问题 I'm a programming noob and didn't quite understand the concept behind callback methods. Tried reading about it in wiki and it went over my head. Can somebody please explain this in simple terms? 回答1: The callback is something that you pass to a function, which tells it what it should call at some point in its operation. The code in the function decides when to call the function (and what arguments to pass). Typically, the way you do this is to pass the function itself as the 'callback', in

Behavior of vector's reserve( ) method

◇◆丶佛笑我妖孽 提交于 2019-12-08 21:26:14
问题 I wanted to know the behavior of std::vector::reserve() in following situations: Suppose reserve(N) is called multiple times one after another immediately. Will the earlier reserve(N1) get added up or overwritten ? If the earlier reserve(N1) gets overwritten with the latest call, then what happens if the latest reserve(Nn) demands less number of slots ? After declaring vector if we have simply push_back() X elements, and then we call reserve(N) . Will the already push_back() X elements

Java OOP Public vs Private vs Protected

牧云@^-^@ 提交于 2019-12-08 19:06:52
问题 I understand what public, private, and protected do. I know that you are supposed to use them to comply with the concept of Object Oriented Programming, and I know how to implement them in a program using multiple classes. My question is: Why do we do this? Why shouldn't I have one class modifying the global variables of another class directly? And even if you shouldn't why are the protected, private, and public modifiers even necessary? It's as if programmers don't trust themselves not to do

When should a virtual method be pure?

醉酒当歌 提交于 2019-12-08 17:34:54
问题 I have found some code that I am working on, and was wondering what the best design implementation is. If a base class defines a method as virtual, but implements an empty body as well, thus not requiring the derived classes to implement a body, should it not be made pure instead? virtual void AMethod1() {} // 1 virtual void AMethod2() {assert(false);} // 2 virtual void AMethod3() = 0; // 3 Current code. Idea1: Alerts user that this derived object has not implemented this method body. Idea2:

How to only allow certain values as parameter for a method in Java?

强颜欢笑 提交于 2019-12-08 17:00:45
问题 I want to write a method that only takes certain values for a parameter, like f.e. in the Toast class in Android. You can only use Toast.LENGTH_SHORT or Toast.LENGTH_LONG as duration for the method makeText(Context context, int resId, int duration) . I had a look at the source code of the Toast class but found nothing there. How can I achieve that? 回答1: Use an Enum Type, from the Java Tutorial, An enum type is a special data type that enables for a variable to be a set of predefined constants

C++. Class method pointers

两盒软妹~` 提交于 2019-12-08 16:23:53
问题 There is a class class A { public: A() {}; private: void func1(int) {}; void func2(int) {}; }; I want to add a function pointer which will be set in constructor and points to func1 or func2. So I can call this pointer (as class member) from every class procedure and set this pointer in constructor. How can I do it? 回答1: class A { public: A(bool b) : func_ptr_(b ? &A::func1 : &A::func2) {}; void func(int i) {this->*func_ptr(i);} private: typedef void (A::*func_ptr_t_)(); func_ptr_t_ func_ptr_;

Impossible to fully qualify class-name in out-of-class declarator of function definition

做~自己de王妃 提交于 2019-12-08 16:22:33
问题 This program results in an undesired parsing greediness dead-end: struct float4x4 {}; class C { float4x4 M(); }; float4x4 ::C::M() { return float4x4{}; } :8:1: error: no member named 'C' in 'float4x4'; did you mean simply 'C'? float4x4 ::C::M() ^~~~~~~~~~~~ Which can be 'fixed' using trailing return type: auto ::C::M() -> float4x4 {} now all good. So I take it we can't fully qualify the class-name when using heading-return-type declarator syntax? 回答1: You can put brackets to disambiguate:

Java - how to read from file when I used PrintWriter, BufferedWriter and FileWriter to write?

谁说我不能喝 提交于 2019-12-08 16:06:31
问题 I have method which writes some data to file. I use PrintWriter , BufferedWriter and FileWriter as shown below public void writeToFile(String FileName){ PrintWriter pw = null; try { pw = new PrintWriter(new BufferedWriter(new FileWriter(FileName))); for(Cars car : list){ pw.println(car.getType()); pw.println(car.getMaxSpeed()); pw.println(car.getOwner()); pw.println(); pw.flush(); } pw.close(); } catch(IOException ex){ System.err.println(ex); } } Now how can I read this data from file? I

Find who's calling the method

白昼怎懂夜的黑 提交于 2019-12-08 15:45:14
问题 I'd like to somehow find out which CFC is calling my method. I have a logging CFC which is called by many different CFC's. On this logging CFC there's a need to store which CFC called for the log. Whilst I could simply pass the CFC name as an argument to my log.cfc, I find this to be a repetitive task, that might not be necessary, if I somehow could find out "who's" calling the method on log.cfc Is there any programmatic way of achieving this? Thanks in advance 回答1: Update : As Richard Tingle