methods

C++ method declaration question

半城伤御伤魂 提交于 2019-12-23 12:01:05
问题 I have some code in Image.cpp: Image::Image( int width, int height, int depth ) : m_sFileName(0) { ... } and in Image.h: class Image: public DrawAble, public RenderAble { ... private : std::string *m_sFileName; }; My question is: what is happening with m_sFilename in the first line? I guess it is set to NULL but what's the point of doing it that way. Would it be the same to do: Image::Image( int width, int height, int depth ) { m_sFileName(0); ... } 回答1: The first uses what's called an

__getattr__ equivalent for methods

那年仲夏 提交于 2019-12-23 11:54:15
问题 When an attribute is not found object.__getattr__ is called. Is there an equivalent way to intercept undefined methods? 回答1: Methods are attributes too. __getattr__ works the same for them: class A(object): def __getattr__(self, attr): print attr Then try: >>> a = A() >>> a.thing thing >>> a.thing() thing Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'NoneType' object is not callable 回答2: There is no difference. A method is also an attribute. (If you want

How to make a method which accepts any number of arguments of any type in Java?

妖精的绣舞 提交于 2019-12-23 11:40:43
问题 I can see there is a way to have a method in Java which accepts any number of arguments of a specified type: http://www.java-tips.org/java-se-tips/java.lang/how-to-pass-unspecified-number-of-arguments-to-a-m.html but is there a way to make a method which accepts any number of arguments of any type? 回答1: All Java Objects extend the Object class. So you can make your function accept an Object array: public void func(Object[] args) { } Or if you want to be able to pass nothing: public void func

Method References like in Java 8 in Scala

ぐ巨炮叔叔 提交于 2019-12-23 10:48:08
问题 In this Java class: import java.util.function.*; public class T { public String func(String a) { System.out.println("There we go: " + a); return a; } public static void main(String... args) { final Supplier<T> c = T::new; final BiFunction<T, String, String> f = T::func; final T t = c.get(); final String v = f.apply(t, "something"); System.out.println(v); } } I can get a method reference to the constructor of T and to the instance method func . Is there a way to do the same in scala, i.e. to

How to not call a function statically in php?

不问归期 提交于 2019-12-23 10:36:58
问题 I am using pear to send mail in PHP. I've followed the example that is on here (http://pear.php.net/manual/en/package.mail.mail.send.php). However, I am getting this error message. Strict Standards: Non-static method Mail::factory() should not be called statically in C:\xampp\htdocs\functions.php on line 43 So I've been trying to get this Strict Standards message to not show up. This is my code: $smtpinfo["host"] = "********"; $smtpinfo["port"] = "587"; $smtpinfo["auth"] = true; $smtpinfo[

How to not call a function statically in php?

℡╲_俬逩灬. 提交于 2019-12-23 10:34:18
问题 I am using pear to send mail in PHP. I've followed the example that is on here (http://pear.php.net/manual/en/package.mail.mail.send.php). However, I am getting this error message. Strict Standards: Non-static method Mail::factory() should not be called statically in C:\xampp\htdocs\functions.php on line 43 So I've been trying to get this Strict Standards message to not show up. This is my code: $smtpinfo["host"] = "********"; $smtpinfo["port"] = "587"; $smtpinfo["auth"] = true; $smtpinfo[

Rails: Passing an Argument to a Concern

半世苍凉 提交于 2019-12-23 10:07:12
问题 DHH wrote an article advocating for the use of concerns. It seems like a good practice, and in a lot of cases, they work well with my app. There are several cases, however, where multiple models have similar but slightly different methods, such as: def find_or_create_membership user_membership = User::Membership.where(:group_id => self.group_id, :user_id => self.invitee_id).first_or_create(:status => "invited") end and: def find_or_create_membership user_membership = User::Membership.where(

Java class keyword

╄→гoц情女王★ 提交于 2019-12-23 09:26:48
问题 I found a few days ago a code in Java that uses the class keyword in the context, for example: MyConcreteClass.class.AMethod(); I've tried to do it in a JFrame, for example: JFrame.class.getName(); And that works but... I can't figure out/find on the internet what this keyword means in that context. I've only used it to declare classes. Can anyone explain me what class means in this context? Thanks, 回答1: In this context class is not a keyword, it's a special attribute (a "class literal") of a

Calling a obj-c method with a parameter

自作多情 提交于 2019-12-23 08:57:03
问题 I've change a c-style function to an objective-c method. As a method, how do i use it? NSString* myfunc( int x ) is now: - (NSString *)myFuncWithParam:(int)x c code: myString = myfunc(x); // works obj-c code: myString = myFuncWithParam(x); // fails to compile. From one of the answers: myString = [object myFuncWithParam:x]; In that case, what would "object" be? 回答1: myString = [object myFuncWithParam:x]; Where object is the object which has the method you're calling. If you're calling it from

Using Dynamic instead of reflection to call method by name

旧城冷巷雨未停 提交于 2019-12-23 08:33:09
问题 Using .NET-4.0, how would I use Dynamic to accomplish the following without using reflection? public void InvokeMethod(string methodName) { Type t = typeof(GCS_WebService); GCS_WebService reflectOb = new GCS_WebService(); MethodInfo m = t.GetMethod(methodName); m.Invoke(reflectOb, null); } 回答1: Dynamic typing in C# doesn't provide for that - the names of the members you want to access still has to be known at compile-time. (You could create the call site yourself of course and use the rest of