ns2脚本语言Tcl的扩展语言Otcl简单介绍<2>

Otcl是Tcl的扩展语言,增加了类的概念,但是和C++又不完全一样,但是ns2模拟中设计的并不太多,

下面给出一个完整的例子,大家看看,熟悉了解一下即可,要是要深入学习,再看大量资料吧。

Class Based    ;#定义 Based 类
Based instproc init { args } {   ;#构造函数
puts "init"
$self set speed_ 0    ;#初始化成员变量
eval $self next $args      ;#显式调用父类的 init 函数
}


Based instproc destroy {} {   ;#析构函数
puts "destroy!"
$self next    ;# $self next 调用父类同名方法
}


Based instproc speed { spd } {
$self instvar speed_    ;#使用类成员变量前需做如此申明
set speed_ $spd
}


Based base    ;#定义 Based 的对象 base,主动调用 init 函数
base speed "fast"     ;#调用 speed 函数
puts "[base set speed_]"   ;#调用 base 类的成员变量 speed_并输出


Class Derived -superclass Based   ;#继承
Derived derived   ;#主动调用父类的 init 方法
derived speed "lower"    ;#调用父类的 speed 函数
puts "[derived set speed_]"


Derived instproc speed { spd } {   ;#重写 speed 方法,实现多态
$self instvar speed_
set speed_ "derived speed"
}


derived speed "spd"  ;#验证多态调用
puts "[base set speed_]"
puts "[derived set speed_]"


derived destroy      ;#调用 destroy 方法销毁 derived 对象
base destroy      ;#调用 destroy 方法销毁 base 对象


上面的例子运行截图如下:


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Overview Tcl Windows API extension overview. Installation Installation requirements and instructions. Win32 raw API Direct access to the Win32 API. Window management Commands related to management of windows. Desktops and Window stations Commands related to desktops and window stations. Windows Shell Windows shell commands. Keyboard and mouse input Simulation of user input and support for system-wide hotkeys. Sound Basic sound functions. Clipboard Commands related to accessing the clipboard. System Operating system and machine configuration and control. Processes, threads and DLLs Commands related to processes, threads and dynamic link libraries. Handles Commands for managing operating system handles. Services Commands for configuring and monitoring Windows services. Network configuration Commands related to network configuration. Disks and Volumes Commands related to disks and volumes. Network shares Commands related to management of network shares. Users and Groups Commands related to user and group accounts. Security and access control Commands related to authentication and access control. Event log Commands relating to reading and writing the Windows event log. Windows INI file Commands for accessing Windows INI files. Console Commands related to Windows consoles. Scheduler Commands related to managing scheduled jobs through the task scheduler. Internationalization Commands related to internationalization. Miscellaneous Various TWAPI ancillary commands. Printers Printer management. Examples Tcl Windows API usage examples. Version History Tcl Windows API extension version history.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值