initializer

How to define extern variable along with declaration?

橙三吉。 提交于 2019-12-03 23:57:05
Wiki says: The extern keyword means "declare without defining". In other words, it is a way to explicitly declare a variable, or to force a declaration without a definition. It is also possible to explicitly define a variable, i.e. to force a definition. It is done by assigning an initialization value to a variable . That means, an extern declaration that initializes the variable serves as a definition for that variable . So, /* Just for testing purpose only */ #include <stdio.h> extern int y = 0; int main(){ printf("%d\n", y); return 0; } should be valid ( compiled in C++11 ). But when

Do these two C++ initializer syntaxes ever differ in semantics?

本秂侑毒 提交于 2019-12-03 20:07:15
问题 Assume that the following code is legal code that compiles properly, that T is a type name, and that x is the name of a variable. Syntax one: T a(x); Syntax two: T a = x; Do the exact semantics of these two expressions ever differ? If so, under what circumstances? If these two expressions ever do have different semantics I'm also really curious about which part of the standard talks about this. Also, if there is a special case when T is the name of a scalar type (aka, int , long , double ,

Reduce function with three parameters

限于喜欢 提交于 2019-12-03 18:01:14
问题 How does reduce function work in python3 with three parameters instead of two. So, for two, tup = (1,2,3) reduce(lambda x, y: x+y, tup) I get this one. This would just sum up all the elements in tup . However, if you give reduce function three parameters like this below, tup = (1,2,3) reduce(lambda x, y: x+y, tup, 6) this would give you a value of 12 . I checked up on the documentation for python3 and it says the third argument is an initializer. That said, then what is the default

Running C++ code outside of functions scope

爷,独闯天下 提交于 2019-12-03 15:56:14
问题 (I know) In c++ I can declare variable out of scope and I can't run any code/statement, except for initializing global/static variables. IDEA Is it a good idea to use below tricky code in order to (for example) do some std::map manipulation ? Here I use void *fakeVar and initialize it through Fake::initializer() and do whatever I want in it ! std::map<std::string, int> myMap; class Fake { public: static void* initializer() { myMap["test"]=222; // Do whatever with your global Variables return

Does Rails run initializers for rake task?

强颜欢笑 提交于 2019-12-03 15:44:16
问题 Are the scripts from config/initializers executed when I run rake task? 回答1: It does if your rake task depends on :environment . i.e, you declare your task like so: task :my_task => :environment do ... end 回答2: Mostly yes. rake loads a complete rails environment including initializers, when your task depends on :environment . 来源: https://stackoverflow.com/questions/11509439/does-rails-run-initializers-for-rake-task

Initializer is inaccessable due to 'internal' protection level

时间秒杀一切 提交于 2019-12-03 10:22:51
问题 I have some protocols LoginStrategy public protocol LoginStrategy { func login(_ viewController: UIViewController) func getUserInfo(withCompletionHandler completionHandler: @escaping (_ userInfo: [String: Any]?) -> ()) func createLoginButton(_ frame: CGRect, withCompletionHandler completionHandler: @escaping (_ loginButton: UIView) -> ()) func getUserId() -> String } and two classes: LoginProvider public class LoginProvider { public let strategy: LoginStrategy public func login(_

Why is an Add method required for { } initialization?

橙三吉。 提交于 2019-12-03 08:31:15
To use initialization syntax like this: var contacts = new ContactList { { "Dan", "dan.tao@email.com" }, { "Eric", "ceo@google.com" } }; ...my understanding is that my ContactList type would need to define an Add method that takes two string parameters: public void Add(string name, string email); What's a bit confusing to me about this is that the { } initializer syntax seems most useful when creating read-only or fixed-size collections . After all it is meant to mimic the initialization syntax for an array , right? (OK, so arrays are not read-only; but they are fixed size.) And naturally it

Running C++ code outside of functions scope

一曲冷凌霜 提交于 2019-12-03 05:20:44
(I know) In c++ I can declare variable out of scope and I can't run any code/statement, except for initializing global/static variables. IDEA Is it a good idea to use below tricky code in order to (for example) do some std::map manipulation ? Here I use void *fakeVar and initialize it through Fake::initializer() and do whatever I want in it ! std::map<std::string, int> myMap; class Fake { public: static void* initializer() { myMap["test"]=222; // Do whatever with your global Variables return NULL; } }; // myMap["Error"] = 111; => Error // Fake::initializer(); => Error void *fakeVar = Fake:

Initializer is inaccessable due to 'internal' protection level

血红的双手。 提交于 2019-12-03 00:53:30
I have some protocols LoginStrategy public protocol LoginStrategy { func login(_ viewController: UIViewController) func getUserInfo(withCompletionHandler completionHandler: @escaping (_ userInfo: [String: Any]?) -> ()) func createLoginButton(_ frame: CGRect, withCompletionHandler completionHandler: @escaping (_ loginButton: UIView) -> ()) func getUserId() -> String } and two classes: LoginProvider public class LoginProvider { public let strategy: LoginStrategy public func login(_ viewController: UIViewController) { return self.strategy.login(viewController) } public func getUserInfo

class member is another class' object

僤鯓⒐⒋嵵緔 提交于 2019-12-02 09:10:10
I am a new C++ user... I have a question regarding how to declare a member of a class "classA" that is an object of another class "classB", knowing that "classB" has a constructor that takes a string parameter (in addition to the default contructor). I did some research online about this issue however it did not help much to help me fix the issue I'm dealing with. To be more specific, I want to create a class that has as member a VideoCapture object (VideoCapture is an openCV class that provide a video stream). My class has this prototype : class myClass { private: string videoFileName ;