initializer

initialize a union array at declaration

夙愿已清 提交于 2019-12-05 07:19:17
I'm trying to initialize the following union array at declaration: typedef union { __m128d m; float f[4]; } mat; mat m[2] = { {{30467.14153,5910.1427,15846.23837,7271.22705}, {30467.14153,5910.1427,15846.23837,7271.22705}}}; But I'getting the following error: matrix.c: In function ‘main’: matrix.c:21: error: incompatible types in initialization matrix.c:21: warning: excess elements in union initializer matrix.c:21: warning: (near initialization for ‘m[0]’) matrix.c:21: warning: excess elements in union initializer matrix.c:21: warning: (near initialization for ‘m[0]’) matrix.c:21: warning:

Twitter integration rails 4 app

谁说胖子不能爱 提交于 2019-12-04 21:00:50
I'm attempting to integrate a twitter feed into my Rails 4 application using this gem . I've read the documentation on the github page but I'm running into a problem when trying to use a method in my view. I have the following in an initializer file named twitter_init.rb (with my auth info): client = Twitter::Streaming::Client.new do |config| config.consumer_key = "YOUR_CONSUMER_KEY" config.consumer_secret = "YOUR_CONSUMER_SECRET" config.access_token = "YOUR_ACCESS_TOKEN" config.access_token_secret = "YOUR_ACCESS_SECRET" end When trying to use the following code in my view I receive the error

Why is an Add method required for { } initialization?

做~自己de王妃 提交于 2019-12-04 13:42:06
问题 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

Rails: Get hostname in an initializer

淺唱寂寞╮ 提交于 2019-12-04 12:38:11
I'm using Sorcery for Authentication, and I need to setup third party authentication in its initializer. The initializer has a line that looks like this: config.twitter.callback_url "http://example.dev/auth/callback?provider=twitter" ...where example.dev is the hostname when I'm using Pow in local development. This needs to be example.com if the app is in production, or staging.example.com if it's in staging, etc. I would like to set this line to be something like this: config.twitter.callback_url "#{Rails.hostname}/auth/callback?provider=twitter" ... but request.host is the only method I know

How to generate initializer in Ruby?

孤街醉人 提交于 2019-12-04 07:39:54
It's time to make it shorter: class Foo attr_accessor :a, :b, :c, :d, :e def initialize(a, b, c, d, e) @a = a @b = b @c = c @d = d @e = e end end We have 'attr_accessor' to generate getters and setters. Do we have anything to generate initializers by attributes? Easiest: Foo = Struct.new( :a, :b, :c ) Generates both accessors and initializer. You can further customize your class with: Foo = Struct.new( … ) do def some_method … end end We can create something like def_initializer like this: # Create a new Module-level method "def_initializer" class Module def def_initializer(*args) self.class

class member is another class' object

做~自己de王妃 提交于 2019-12-04 06:28:14
问题 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

Why do I get an error about the initializer not being a constant?

孤者浪人 提交于 2019-12-04 02:57:24
问题 I am using the following code. const int X_ORIGIN = 1233086; const int Y_ORIGIN = -4728071; const int Z_ORIGIN = 4085704; const int xyzOrigin[NUM_DIMENSIONS] = {X_ORIGIN, Y_ORIGIN, Z_ORIGIN}; When I compile it, GCC gives me the following error. Transformations.h:16:1: error: initializer element is not constant What does that mean? How can I fix my code? 回答1: You can't do this at global scope in C, only at local scope, i.e. within a function: #define NUM_DIMENSIONS 3 const int X_ORIGIN =

Rails initializers are running while migrating database

别来无恙 提交于 2019-12-04 01:59:37
It is very surprising that Rails's initializers run while running any rake task, including db:migrate and db:seed . An initializer in my app starts a background thread (a kind of worker process), and it should be executed only when the application is running in debug and production mode. How to prevent a specific initializer from running when doing rake db:migrate or how to detect in initializer that a rake task is running? Here is a solution how to prevent an initializer from running in Rake task: unless ( File.basename($0) == 'rake') # Initializer code end Alessandro Gurgel If your

In what order are initializer block and variable definitions and etc. executed? (in java)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 01:58:13
I have problem understanding the order in which initialization happens. this is the order I assumed: *Once per 1. Static variable declaration 2. Static block *Once per object 3. variable declaration 4. initialization block 5. constructor but according to this code I am obviously wrong: class SomethingWrongWithMe { { b=0; //no. no error here. int a = b; //Error: Cannot reference a field before it is defined. } int b = 0; } And the error would disappear if I do this: class SomethingWrongWithMe { int b = 0; { b=0; int a = b; //The error is gone. } } I can't figure out why isn't there an error on

C++ Array Initializers Warnings

不羁岁月 提交于 2019-12-04 01:44:43
问题 I have declared and initialized a constant char array within a class: class grid { const char test[11] = {'s', 'e', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; My code works, but I keep getting compiler warnings: non static data member initializers only available with C++11 and extended initializer lists only available with C++11 I know that this isn't an issue because I'm compiling to C++11 standard, but I'm curious as to what is pre C++11 about my code. I am hoping someone can give me