我有一个类消息的实例,我将调用" msg"。我已经定义了一个班级" my-message"并希望实例" msg"现在属于那个班级。
听起来我觉得它应该相对简单,但我不知道该怎么做。改变班级给了我一个我不明白的错误。
(defclass my-message (message)
((account-name :accessor account-name :initform nil :initarg :account-name)))
(change-class msg 'my-message :account-name account-name)
ERROR :
While computing the class precedence list of the class named MW::MY-MESSAGE.
The class named MW::MESSAGE is a forward referenced class.
The class named MW::MESSAGE is a direct superclass of the class named MW::MY-MESSAGE.
答案 0 :(得分:4)
Sub breaking_count() Const Area_x As String = "$D$9:$I$9" Const Area_y As String = "$K$9:$P$9" Dim Nr As Integer, Count_x As Integer, Col_Ind Dim temp_Area As Range For Nr = 4 To 1 Step -1 'With Worksheets(CStr(Nr)) With Worksheets(Nr) If WorksheetFunction.CountIf(.Range(Area_y), "*y*") > 0 Then 'find the index of "y" in Area_y Col_Ind = WorksheetFunction.Match("y", .Range(Area_y)) 'Reset the range Area_y in temp_Area using offset Set temp_Area = .Range(.Cells(9, 4).Offset(0, Col_Ind), .Cells(9, 9)) Count_x = Count_x + WorksheetFunction.CountIf(temp_Area, "*x*") Else Count_x = Count_x + WorksheetFunction.CountIf(.Range(Area_x), "*x*") End If MsgBox Worksheets(Nr).Name & " : " & Count_x Count_x = 0 End With Next End Sub
前向引用类是您引用但尚未定义的类。如果查看类的名称,则为The class named MW::MESSAGE is a forward referenced class.
。我想你想在另一个包中继承另一个名为MW::MESSAGE
的类;您导入的符号可能有问题。
MESSAGE
由于尚未定义The class named MW::MESSAGE is a direct superclass of the class named MW::MY-MESSAGE.
类,因此无法创建它的实例。这也是您无法创建任何子类的实例的原因,例如MW::MESSAGE
。
答案 1 :(得分:4)
这对我有用:
CL-USER> (defclass message () ())
#<STANDARD-CLASS COMMON-LISP-USER::MESSAGE>
CL-USER> (defparameter *msg* (make-instance 'message))
*MSG*
CL-USER> (describe *msg*)
#<MESSAGE {1002FE43F3}>
[standard-object]
No slots.
CL-USER> (defclass my-message (message)
((account-name :accessor account-name
:initform nil
:initarg :account-name)))
#<STANDARD-CLASS COMMON-LISP-USER::MY-MESSAGE>
CL-USER> (change-class *msg* 'my-message :account-name "foo")
#<MY-MESSAGE {1002FE43F3}>
CL-USER> (describe *msg*)
#<MY-MESSAGE {1002FE43F3}>
[standard-object]
Slots with :INSTANCE allocation:
ACCOUNT-NAME = "foo"
请注意,这不是强制转换,因为对象本身会被更改。它现在是另一个类的实例。 cast 通常意味着只是在某些情况下对未更改的内容的解释会发生变化。但这里的实例确实发生了变化,旧的解释不再适用。