我正在尝试理解界面.
根据我对接口的了解,它们与类一起使用,并允许将类附加到接口类?我不太明白这个概念.何时以及为什么要使用此功能?我正在阅读一本书,将行为放入课堂,然后通过连接一个共同的对象可以有多种行为?
创造类似的东西
Vehicle myObject = new Vehicle();
Interface1 something = myObject;
something.someFunc();
Interface Interface1 {
void someFunc();
}
Run Code Online (Sandbox Code Playgroud) 根据不同的语法和可以使用的地方,它们似乎都非常密切相关.有哪些主要区别?
我创建了一个Spam类型的新对象,attr_accessor同时具有hooray和name,我有初始化方法.我期待当我创建一个新对象时,该对象加载了一个带有"Whammy"的var变量和一个名为hooray的空数组.虽然我没有得到这种行为.谁能解释一下,谢谢你提前.
module Test
class Spam
attr_accessor :hooray, :name
def initialize
hooray = []
name = "Whammy"
end
end
end
Loading development environment (Rails 3.0.0)
irb(main):001:0> require 'Test'
=> nil
irb(main):002:0> test = Test::Spam.new
=> #<Test::Spam:0x000000031ff470>
irb(main):003:0> test.name
=> nil
irb(main):004:0> test.hooray
=> nil
irb(main):005:0> test.hooray << 5
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.<<
from (irb):5
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands/console.rb:44:in `start'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands/console.rb:8:in `start' …Run Code Online (Sandbox Code Playgroud) 什么是| 意思?
m_pD3DDevice->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE);
Run Code Online (Sandbox Code Playgroud) 阅读谷歌后,我仍然不太明白这是什么/意味着什么?有人可以解释一下吗?可能是一个简单的例子?非常感谢你.
我该如何解决这个问题?我还能看到哪些其他信息?
An unhandled exception of type 'System.TypeInitializationException' occurred in Microsoft.VisualStudio.HostingProcess.Utilities.dll
Run Code Online (Sandbox Code Playgroud)
附加信息: The type initializer for 'SpaceShip.Program' threw an exception.
结构可以与类同名吗?
我可以将结构传递给函数吗?
结构是轻量级的?基本上没有功能.它是一个容纳变量的容器.我只是想知道我是否创建了一个函数,我可以传入一个像通常传入任何其他对象的结构吗?