友元函数、友元类、访问私有数据成员、友元关系[C++]

 

【来源】http://scudong.blogbus.com/logs/46868663.html & 作者声明

友元函数(friend function)
1. 什么是友元函数?
一个类的私有数据成员通常只能由类的函数成员来访问,而友元函数可以访问类的私有数据成员,也能访问其保护成员
2. 友元函数的用处体现在哪里?
2.1 使用友元函数可提高性能,如:用友元函数重载操作符和生成迭代器类
2.2 用友元函数可以访问两个或多个类的私有数据,较其它方法使人们更容易理解程序的逻辑关系
3. 使用友元函数前应注意:
3.1 类的友元函数在类作用域之外定义,但可以访问类的私有和保护成员
3.2 尽管类定义中有友元函数原型,友元函数仍然不是成员函数
3.3 由于友元函数不是任何类的成员函数,所以不能用句柄(对象)加点操作符来调用
3.4 public, private, protected成员访问符与友员关系的声明无关,因此友元关系声明可在类定义的任何位置,习惯上在类定义的开始位置
3.5 友元关系是指定的,不是获取的,如果让类B成为类A的友元类,类A必须显式声明类B为自己的友元类
3.6 友元关系不满足对称性和传递性
3.7 如果一个友元函数想与两个或更多类成为友元关系,在每个类中都必须声明为友元函数
4. 注:由于C++属于混合语言,常在同一个程序中采用两种函数调用且这两种函数调用往往是相反的。类C语言的调用将
基本数据或对象传递给函数,C++调用则是将函数(或信息)传递给对象 继续阅读友元函数、友元类、访问私有数据成员、友元关系[C++]

8900设备未就绪

向8900+8G TF卡上传音乐,提示设备未就绪。折腾了一中午。

方法一:

右键–可移动磁盘–属性–硬件–选 RIM BB SD–再点属性–策略–为提高性能而优化–确定

方法二:

将多媒体文件压缩后拷到BB上然后再解压缩。

两个方法都在用,暂时没问题了。

Ubuntu 10.04 安装 Google Pinyin输入法

【来源】

A. 获取代码:(没有git的先安装git:sudo apt-get install git-core

$ git clone git://github.com/tchaikov/scim-googlepinyin.git

$ cd scim-googlepinyin.git

B. 编译前提:

上面给的链接里面有介绍怎么编译的,但少提了几个必需组件,这里列一下:

* autotools-dev

* libgtk2.0-dev

* libscim-dev

* libtool

* automake

用下面命令看看是不是安装了,如果没有,会自动帮你安装上:

$ aptitude install autotools-dev libgtk2.0-dev libscim-dev libtool automake

C. 编译:

记住系统必须先存在SCIM(没有的话 sudo apt-get install scim 一下)

$ ./autogen.sh

$ make

$ sudo make install

现在重启scim:

关闭scim:

$ pkill scim

然后启动:

$ scim -d

OK,去首选项里的“语言支持”的“输入法”选择scim作为默认输入法就OK了。

win7 路由上网DNS服务器无响应问题的解决方案

原文发表于:adaier.com

从周六开始,用Win7就一直上不了实验室的网,提示是DNS服务器无响应。一开始以为是电脑中毒之类的问题,就花了一天时间重装系统。还是上不了网。就跑图书馆折腾一下午。奈何网速太慢,到现在还没下完所有的更新,很多软件也还没有装好。上网找来一堆解决办法。结果是能Ping同本地和路由,DNS一直Ping不通。其他的办法也都一一试过了,不行涅。现在只好又转到Ubuntu下面,然后用VirtualBox装一个XP的虚拟机,再在里面装VS2005。哎,这道路也太曲折了吧。哪位高手能帮忙解决下这上网问题阿?

[来源:互联网]

说法1.

1.首先可以

开始运行 输入CMD

然后输入 ping 127.0.0.1

如果ping

说明TCP/IP协议没有问题

ping不通请重装TCP/IP协议

2.然后ping自己的默认网关(default

gateway) 默认网关可输入ipconfig

/all查看 ping通说明路由设置没有问题

ping不通应该是路由有问题

3.网络诊断说DNS服务器无法连接

这个有可能是学校DNS服务器的问题

如果其他同学可以上网 你是不是忘了把DNS域名服务器也改成自动获取

如果其他同学也上不了 联系学校吧 告诉他们DNS服务器有问题了

说法2.ARP攻击的状况)

解决方法一 MS-DOS窗口下运行命令arp

-d后即可恢复上网。

解决方法二

第一你先安装ARP防火墙,第二删除C:\WINDOWS\system32\

NPPTools.dll 系统文件。

说法3.

其实从根本上来说还是VISTA系统本身的兼容性很差和一些系统程序有自动识别功能的缘故.

一般的VISTA系统的电脑都会在连接本地网络和INTERNET都正常能用的情况下用WINDOWS网络诊断进行诊断的结果是无法与DNS(服务器号码)通信,同时数据包的发送和接收的数据也有一定的差距….现在一般性的电脑维护人员都无法解决.

当设置为IP地址等都为自动获取的状态下.网络状态有时为连接状态。但有时却无法连接….

这些像开始几天都能上网但是一段时间后会根本无法连接INTERNET貌似基本相似的毛病:当电脑显示为“仅本地”时,你用网络诊断进行诊断和修复看此问题有没有被修复?不行时再去在主机上对IP

进行重新的设定,然后自己电脑上再进行手动设置IP等地址等….然后看是否已经连接

再不行可以打电话给该品牌电脑售后维修人员对其进行一些指导。

说法4.

系统更多考虑了安全问题,你的IP设置为自动获取,其实是从DHCP服务器获取IP及相关参数,但是这个过程可能由于某种原因,没有完成.在SP1时代,这种情况下,操作系统为了防止脱网(微软这么写的),自作主张为网卡设置169.x.x.x的保留IP,不作任何错误提示,如果有多台计算机没有获得正确的IP,那么他们通过保留地址还可以互相通讯。

但是安装SP2后,操作系统依据“安全”至上的原则,不分配任何IP,切断网络连接,并报告错误“本地连接受限制或无连接”。

一般的情况是网卡不能绑定IP造成的,有的时候修复可以解决,但是很多时候修复是不起作用的,原因比较复杂,一般是网络造成的,与系统或者计算机本身没有关系,现在列举出排查的方法:

方法1

打开“控制面板”——“网络连接”,找到当前的本地连接,右击它,选“属性”,在“常规”选项卡中双击“Internet协议

(TCP/IP)”,选择“使用下面的IP地址”,在“IP地址”中填写“192.168.0.1”,在“子网掩码”中填写

255.255.255.0”,其他不用填写,然后点“确定”即可解决该问题。(如果当前计算机加入工作组或域,就要根据情况而设置)

方法2

可以在“网络连接“的”本地连接“的设置里把”无连接时通知我“的选项去掉就行了

方法3

控制面板,管理工具,服务

把里面的dhcp client服务设置为自动

然后把这个服务启动起来

方法4

禁用网卡再启用

方法5

1.安装一个什么网络快车OR星空极速的软件(电信安装ADSL给你的时候给你的,或上网下载)就行

.

 

2.如果你不安装拨号软件也可以,那就需要新建一个拨号连接,具体怎么做就自己试吧.反正岔路不多

:我记忆中好象用ADSL上网,没拨之前那个连接受限是正常的,此时的IP地址应该是169…..的私有地址,但只要你拨上去就会正常了……

方法6

IP变成169开头的(显示连接受限)是怎么回事

这个IPWindows系统在向dhcp服务器发出请求后没有响应的情况下系统为自己保留的一个IP地址。也就是说当你的地址变成169开头的时候是因为没有和dhcp

服务器连接成功,可能的原因有几个第一个可能是网线没有连接好,虽然物理上显示有连接成功但是实际上数据是跑不通的。第二个是由于防火墙阻碍了与DHCP服务器通信,可以检查防火墙规则或者关闭防火墙。第三个原因可能是由于自己主机的网卡的MAC地址全为0。可以尝试重新安装网卡驱动解决。第四个原因如果一个宿舍都出现这样的情况检查宿舍主线是否连接正常,首先是物理连接也就是说连接到墙上端口的网线对应交换机的灯是否亮着。其次是检查自己交换机是否有问题,简单的办法是找一根网线从墙上直接接到电脑上看是否可以上网。

这里再说一个简单的判断是硬件问题还是软件问题的方法,手工指定一个同宿舍其他人正在使用的电脑的IP,如果对方和自己都提示冲突那么说明是软件原因。那么检查防火墙和主机设置,特别是dhcp服务是否启动。如果不提示冲突那么就是硬件原因。检查网线物理连接网卡等等。

方法7

出现这种情况多半是因为路由设备没有启用DHCP,而系统的默认设置为自动获取IP地址,这样,在无法自动获取IP时,就会出现“本地连接受限或无连接”

的错误提示。这在有线连接和无线连接都有可能会出现。解决的方法就是手动给计算机设定一个IP地址,至于设定什么样的IP地址,子网掩码是多少,网关如何设定,请咨询网络管理员。

1.根治方法,具体操作如下:

控制面板→网络连接→本地连接→属性→双击“tcp/ip协议

。在使用下面的ip地址使用下面的DSN服务器地址填写你的地址.

一般情况下,对应输入以下内容就可以解决:

IP地址:192.168.1.2

子网掩码:255.255.255.0

默认网关:192.168.1.1

DNS服务器():202.102.192.68

DNS服务器():202.102.199.68

2.

治标方法,如果觉得上面的设置麻烦,那也没有关系,把提示去掉就可以,对网络没有影响.

具体操作如下:

控制面板→网络连接→本地连接→属性→把此连接被限制或无法连接时通知我前面的钩去掉.

方法8

先检查一下网线由你的电话线到猫,再到路由器(如果有,呵呵)再到电脑是否都连接正常,最重要的是你的水晶头是专业人士做的(如果水晶头有问题,麻烦大了)。如果都没有问题,在电脑里卸载你的网卡,在设备管理器里重新点操作,刷新,就是检测硬件改动!在看看你本地连接是否正常。如果还是感叹号,你点本地连接右键属性,先点TCP,IP一下在点属性。再点使用下面的IP地址:

输入IP地址:192.168.1.100

子网掩码:255.255.255.0默认网关:192.168.1.1

然后点,使用下面的DNS服务器地址输入:202.101.103.55

最后再看你的本地连接,或者上网试试,如果不行,你重换个网卡,很有可能你的网卡是主板集成的坏了。

VirtualBox让GUEST识别USB设备

顺利搞定IPod同步的问题。越发觉得Ubuntu无所不能了的说。

【来源一】

方法1:

Terminal下输入命令:
$ sudo gedit /etc/fstab

在末尾加上
# the USB group
# 对所有用户开放USB设备的读写权限
none /proc/bus/usb usbfs devmode=666 0 0

然后就可以在VirtualBox的USB filter中加入需要在guest中使用的USB设备了。 但是把USB设备的读写权限开放给所有用户的方式在一些情况下不太安全。

———————————————————————————–

更为稳妥的做法:

1.增加用户组usbfs
$ sudo groupadd usbfs

2. 查看usbfs用户组的gid(不一定是1002)
$ cat /etc/group | grep usbfs
usbfs:x:1002:

3.把当前用户增加到usbfs组(****:你的用户名)
$ sudo gedit /etc/group
把 usbfs:x:1002:
修改为 usbfs:x:1002:*****

4. 为USB设备重新设置权限编辑/etc/fstab文件,添加下面两行,注意你的gid可能不是1002
$ sudo gedit /etc/fstab
在末尾加上:
# 1002 is the USB group IDI
none /proc/bus/usb usbfs devgid=1002,devmode=664 0 0

重新启动后,应该就可以在客户机中使用USB设备了 。插入一个USB设备后,如U盘,右键点击虚拟机里右下脚的USB图标,选择已经识别的U盘,就可以正常使用了。注意:(1)在客户机里使用USB设备前要先在主机里卸载。 (2)完成后重启系统

———————————————————————————–

【来源二】

方法3:

打开“用户和组”, 解锁, 把自己的帐号添加到vboxusers组里。详细的操作是:

1

Go to System -> Administration -> Users and Groups…
系统->系统管理->用户和组。

2

Click the “Unlock” button…
点“解锁”。

3

Type your password and click the “Authenticate” button….
输入密码后点认证。

4

Click on the “Manage Groups” button…
点“管理组”。

5

In the “Groups settings” window that will appear, scroll down until you see the vboxusers entry. Select it and then click on the “Properties” button…
在接下来显示的“组设置”窗口中选中“vboxusers”点击“属性”。

6

Another window will appear, called “Group ‘vboxusers’ Properties. Just check the box in front of your username and click the “OK” button when you’re done…
在“组’vbosusers‘的属性”窗口,勾选自己的用户名并点“确定”。

7

Close the “Group settings” and “Users Settings” windows and log out. Log in and open up VirtualBox, start your virtual machine and you will see that you can now access the USB devices!
重新登录后就可以在虚拟机中使用USB设备了。

8

Ubuntu Host WinXP Guest 文件共享设置

很多文件都需要在两个系统下面轮流处理。现在还没有找到让WinXP用USB盘的方法,倒是直接设置文件共享来的简单。比较有意思的是我把Ubuntu的Desktop设为共享文件夹之后原来还要好麻烦的切换鼠标和键盘独占状况,这会儿就像是在同一个系统的不同窗口切换一样方便。

来源:www.ludou.org

在VirtualBox中安装好Windows XP后,先要安装工具包VBoxGuestAdditions.iso,这个映像文件位于VirtualBox的安装目录下,我的是在/usr/share/virtualbox目录下。VirtualBox控制面板中点击“设置”,接着选“光驱”,加载映像。启动虚拟机进入XP后,安装辅助工具包。

接下来是设置共享目录了。在VirtualBox先选择你的虚拟系统,接着“设置”,选“数据空间”,点击那个加号按钮,出现添加数据空间的窗口,“数据空间位置”中点击“其它”选择你要共享的文件夹,“数据空间名称”中填你自己起的名字,这里我填的是tmp,只读选项根据自身情况选择。

接着启动进入客户机Windows XP,打开“我的电脑”,依次点击菜单栏“工具”-“映射网络驱动器”,驱动器盘符自行选择,文件夹填“\\vboxsvr\tmp”,tmp是我之前设置的“数据空间名称”,把tmp改成你刚才设置的“数据空间名称”即可。确定后,在“网络驱动器”那里就可以看到共享文件夹的盘标了。好了,现在双击“网络驱动器”中的那个图标,即可读取、修改linux主机中的文件了。

全面Unbuntu中

 

因为有HP的备份系统,系统重装从来不是复杂的事情。就塞张还原盘进去,重启,让电脑自己干活去。上周末心血来潮又要重装系统。结果是用的光盘坏掉又没带来米国备份的,同时神使鬼差的把硬盘上的备份也给革掉了。第二天心急火燎的跑到实验室问人借系统安装盘,Marc的winVista没有注册码,阿基琉斯的Debian又是白痴中,就想到了Ubuntu了。

背上两台电脑(一台背包里一台挎包里头,呃,累。。。),一过5点就跑回来去UVa的Bookstore买了一盒DVD-R,回家开始刻。。。原来电脑上的数据还好,在Windows仅剩的DOS里面用XCopy把所有照片和文档都转到移动盘上了。然后干脆把全盘装成Ubuntu。

这会儿还是磕磕绊绊的用着。Ubuntu的好处是速度快多了,几乎所有的软件都可以免费用(这点对中国人没啥用哈)。只是好多东西都要自己调试,总会有各种各样的问题要fix,还有软件都不如windows里的专业(免费的么那比得上商用)。特别是之前用的超级顺手的WLW还有Photoshop都找不到好的替代品,还有ipod不能同步是个大问题。解决办法呢,Windows虚拟机。网上比较推荐的虚拟机主要有wine和virtualbox,网上对比的文章已经放到空间里了。

每次装Ubuntu要设置的东西都差不多的说。菜鸟的解决办法是:

------------------------

输入法:把新立得里面所有带zh貌似和中文输入有点关系的都装上。

------------------------

影音:mplayer,需要安装rmvb的解码器
下载:http://www1.mplayerhq.hu/MPlayer/releases/codecs/all-20071007.tar.bz2
解压后在terminal中进入解压后的文件夹所在的文件夹

sudo mkdir /usr/lib/codecs/
sudo mv essential*/* /usr/lib/codecs/

------------------------

skype音频的问题:
进入到skypeaudio选项,把声音输出改为pulse,话筒的话每个选项都试下,总有一个合适的。

------------------------

FlashPlayer中文显示:
sudo gedit /etc/fonts/conf.d/49-sansserif.conf
最后第四行的san-serif改成 文泉驿正黑

[zz]Windows Application Emulation: Wine vs VirtualBox

介绍得很详细。先放上来先,省得以后难找,或者是压根儿上不了。

Source:http://www.raiden.net/?cat=2&aid=394


Written by Steve Lake
Posted on: Mar 26, 2008 at 07:36am
Section: Software
Tags: none | Edit Tags!
Printer Friendly Version
Legacy URL

In my ever ongoing efforts to completely shed all connections to Microsoft Windows and all Windows applications, including 3rd party ones, I’ve been doing a lot of research over time into various methods by which I could make that one final push to completely shed all of those lingering connections. But alas, it’s been much harder than I could have expected. That’s not to say it’s impossible, but there certainly seems to be a lot of things out there bent on NOT letting me make that last step. So it’s less an issue with what I’m doing or not doing, and more a case of forced adherence to a system I’d like to separate myself from.

There’s many reasons why I want to rid myself of this connection. Here are the three biggest that I believe drive this interest.

  1. Viruses – I may not see many viruses on my system, but then again I’m also very alert to what’s happening and I’m constantly keeping all my defenses and protections up to date and running well in order to fend this off.
  2. Spyware – I can’t even begin to tell you how much I abhor spyware. Be it intrusive web ads, spyware apps, malware, or any of a variety of other things.
  3. Proprietary Software – Now not all proprietary software is bad. However, the main platform it runs on and the vast majority of applications written to run on it are. There’s little to no accountability from the OEM (unless it’s forced by the end users, and even then that accountability is weak), and issues are handled on a "money" focused, rather than "end user" focused priority.

That’s why I’m so interested in Open Source software systems, including operating systems (Linux, BSD, etc), end user software (Firefox, Open Office, etc), user interfaces (KDE, Gnome, XFCE, etc) and so much more. The software is open, the developers are accountable to the end users, and the software tends to be more secure and reliable. Those developers who choose not to do the will of the community, unless it’s for the better of the community, tend to be abandoned and left to atrophy while good projects that do keep themselves accountable to the user base succeed.

But enough with this little sermon. If you’re reading this, you likely either already know about this, or have heard enough to know the facts. So I’ll move on to the main focus of this article. Comparing the two major forms of in-system emulation of Windows applications. No matter how hard you try, unless you’ve committed yourself to giving up any and all Windows based applications, you tend to find yourself stuck in a situation where you must emulate at least one of these applications inside of Linux. This is where emulators such as Virtual Box and Wine come in handy to help you bridge that divide.

The best way to understand the pros and cons of doing something like this vs going "cold turkey" on all windows applications is to look at the pros and cons of each of the emulation systems and see if they meet your needs, or if you may have to take more drastic steps such as dual booting or other such measures. Below I’ve created a list of all the pros and cons I’ve come up with for Virtual Box and Wine, the two main emulators out there. I’ve also included a third line for "dual booting" for comparison.

Pros:

Virtual Box

  • Full compatibility with the vast majority of Windows applications
  • Easy setup
  • Native Windows environment, even if it is emulated
  • Direct sharing of applications and data between Windows and Linux programs.
  • Allows most Windows games to run.

Wine

  • No need for a full copy of Windows.
  • Integrates seamlessly with window manager in most cases.
  • Direct sharing of applications and data between Windows and Linux programs.
  • Allows some, mostly older games to run.
  • Drive space is shared on the system between the Windows and Linux apps.

Dual Booting

  • 100% compatibility of all applications.

Cons:

Virtual Box

  • Not all applications work in Virtual Box. Applications and games that refuse to run in a "debug" environment, such as Halo, will not run.
  • Consumes a sizable amount of hard drive space.
  • Consumes a fair amount of resources under load.
  • Requires a copy of Windows plus a valid Microsoft license.
  • Emulated OS is still vulnerable to viruses.
  • Slow application installs.
  • System tends to grind to a halt under normal use.
  • "seamless mode" can still get in the way of your regular system. IE, taskbar overrides KDE bar, XP windows overrule Linux windows, etc.
  • Games can be slow to unusable.

Wine

  • May require a valid Windows license for compatibility and legality issues, even if you don’t need a copy of Windows, depending on what programs you want or need to run and what Microsoft support applications are required to be installed.
  • Slow application installs.
  • Application hangs are common depending on the application and scripting used to install it.
  • Tools for aiding application installation are a bit buggy.
  • Requires a fair knowledge of Linux administration to setup and configure for each application.
  • Not all applications are supported, or supported correctly. Rarely are newer applications supported.

Dual Booting

  • Requires a valid copy of Windows.
  • Requires that you reboot to get to your Windows desktop.
  • No direct sharing of applications and resources between Windows and Linux programs.
  • Takes up additional hard drive space.
  • Difficult to make Windows talk to Linux drives properly.

This list is just a summary of some of the pros and cons of using these two different methods for running Windows applications in Linux. Now again, dual booting is not an emulation method to allow Windows applications in Linux, but it does provide a comparison between the two emulation methods, and a natively installed system, even if it is technically dual booting. Now if you’re wanting to run games in Linux, some of what you run into is hit and miss success. Here’s some examples of some common newer games vs older games and how they run in the two emulation systems. This isn’t a complete list by far, but it does provide some comparisons.

Game Virtual Box Wine
Halo Won’t play at all. Complains about "debug" mode. Won’t play at all. Complains about "debug" mode.
Starcraft Runs decently. Runs Flawlessly.
World of Warcraft Runs decently. Runs well.
Most C&C games Run slowly, but still run. Most run well, except newest versions
Warcraft 3 Runs well. Runs Flawlessly.
Medal of Honor (most games) Runs decently. Runs well.
Call of Duty (1 and 2) Runs slowly. Runs decently.
Call of Duty 4 Runs slowly. Won’t run.
Freelancer Won’t play at all. Complains about "debug" mode. Won’t install. Can’t write to disk.

 

Again, this list is just a sampling based on some stuff I had on hand and doesn’t cover all the games I tested, but does provide a sampling that best represents the general experience overall. So it hopefully it gives you an idea of what you’re up against. Overall, I’d say that the games I had the biggest issues with were the Microsoft games. Not surprising really, but disappointing none the less. The ones I had the best luck with were the Blizzard games.

Now on the question of applications, that varied quite a bit, and while some ran well, others were an utter joke. Here’s a sampling of the programs I tested and generally how they came out.

 

Program Name Virtual Box Wine
Internet Explorer 6 Runs very good. Runs very good.
Adobe Photoshop (7.0 and earlier) Runs flawless, but a bit slow. Runs well, and speed is good.
Adobe Photoshop (CS series) Runs decent. Good luck getting this to run most of the time.
Thumbs Plus (most versions) Runs Flawlessly. Runs Flawlessly.
DVD Decrypter Runs Flawlessly. Runs Flawlessly.
Microsoft Office (2000-2007) Won’t run (2007), runs decent (2003), runs good (2000) Won’t run (2007), runs good (2003), runs good (2000)
Winrar Runs good. Runs Great!

 

Again, this is just a sampling of what I tested and they are listed in the most representative manor to relay what I ran into during testing in the best way possible. The "good", "great", "poor", etc ratings count both performance and stability into one rating since stability without performance or vice versa really doesn’t make for a good experience. Both have to be good to get a good rating. Overall though, depending on what you need to do, I feel that from my testing the better choice overall is to use Wine for all your emulation over Virtual Box. Sure, Virtual Box with an emulated copy of Windows XP can give you some flexibility that Wine doesn’t have.

However, given the legal and licensing entanglements, it may be better to use Wine for everything you can, and then just run the rest via a dual boot setup in a native Windows environment until either Wine does everything for you, or you no longer need that application or game anymore. Now I did like Virtual Box and all it offered, but given all the potential licensing entanglements, plus the fact that you’re running a restrictive proprietary OS inside a free and open source operating system, even if it is emulated, it’s still a rather questionable ethical and legal choice.

I hope this has been a helpful overview and if you have any questions, please feel free to ask in the forums. Thanks!

Matlab->.mat文件序列

Alice同学给布置的作业。用Matlab生成编了号的.mat的文件序列。备份下免得以后没地方找。

for k=1:3
    b(k)=NaN(8,1);
    s=sprintf(‘m%d=magic(%d);save m%d.mat b(%d)’,k,k,k,k);
    eval(s);
end

这样下来文件夹里就有m1.mat, m2.mat和m3.mat三个文件。