Tag: 类的

C ++类/结构成员的默认可见性

在C ++中,为什么private是类成员的默认可见性,而public是结构体?

C#错误“types初始值设定项…抛出exception

此错误仅在某些计算机上发生。 通过读取堆栈信息,在静态类中调用此静态方法(“FormatQuery”)时会出现一些问题: using System; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.IO; using System.Text; using System.Windows.Forms; using DevExpress.XtraEditors; using FlexCel.Report; using FlexCel.XlsAdapter; using ComboBox=System.Windows.Forms.ComboBox; namespace XSoftArt.A { static class RHelper { private static string FormatQuery(string FieldName, int Count, CheckedListBox chekedListBox) { string ID = string.Empty; int n = Count; foreach (DataRowView item in chekedListBox.CheckedItems) { […]

“英雄”这个类名是从哪里来的?

一个被广泛采用的CSS命名实践是使用hero作为应用于网站主标题的类名。 这个命名约定是从哪里来的,特别是对某些事情的参考?

重新定义类方法或类

有没有办法重新定义一个类或它的一些方法,而不使用典型的inheritance? 例如: class third_party_library { function buggy_function() { return 'bad result'; } function other_functions(){ return 'blah'; } } 我能做些什么来取代buggy_function() ? 显然这是我想要做的 class third_party_library redefines third_party_library{ function buggy_function() { return 'good result'; } function other_functions(){ return 'blah'; } } 这是我的确切困境:我更新了一个破坏我的代码的第三方库。 我不想直接修改库,因为将来的更新可能会再次破坏代码。 我正在寻找一种无缝的方式来取代类方法。 我发现这个图书馆说它可以做到这一点,但是我已经4岁那么警惕了。 编辑: 我应该澄清说,我不能从third_party_library重命名为magical_third_party_library或其他因为框架的限制。 对于我的目的,是否可以只为课程添加一个函数? 我想你可以在C#中做一些叫做“部分类”的东西。

Java如何决定何时导入?

为什么Java不需要导入像Integer,String等类,而需要导入其他类呢?

PHP中的dynamic类属性$$值

我怎样才能知道只有一个string的类属性? class Foo { public $bar; public function TestFoobar() { $this->foobar('bar'); } public function foobar($string) { echo $this->$$string; //doesn't work } } 什么是评估string的正确方法?

扩展方法与inheritance

有什么经验法则可以帮助确定在哪种情况下使用哪种? 我应该比其他大多数时间更喜欢一个吗? 谢谢!

如何使用reflection在构造函数中使用参数创build类的实例?

例如: public class Test { public static void main(String[] args) throws Exception { Car c= (Car) Class.forName("Car").newInstance(); System.out.println(c.getName()); } } class Car { String name = "Default Car"; String getName(){return this.name;} } 清除代码。 但是,如果我用params添加构造函数,有些像这样: public Car(String name) {this.name = name;} 我看到: java.lang.InstantiationException 所以,不,我不知道,如何通过params构造函数。 请帮忙。

PHP是面向对象的吗?

PHP是一种面向对象的语言吗? 如果没有,那么CakePHP的框架呢? 它是PHP的面向对象的MVC实现吗? 另外,完全使用类构build的PHP应用程序可以称为面向对象吗?

在类的构造函数中返回一个值

到目前为止,我有一个PHP类的构造函数 public function __construct ($identifier = NULL) { // Return me. if ( $identifier != NULL ) { $this->emailAddress = $identifier; if ($this->loadUser() ) return $this; else { // registered user requested , but not found ! return false; } } loadUser的function是查找特定电子邮件地址的数据库。 当我设置标识符到一些电子邮件,我敢肯定它不在数据库中; 第一个IF被通过,并且进入第一个ELSE。 这里的构造函数应该返回FALSE; 但相反,它将返回具有所有NULL值的类的对象! 我如何防止这个? 谢谢 编辑: 谢谢大家的答案。 这相当快! 我看到OOP的方式是抛出一个exception。 所以抛出一个,我的问题改变,我应该怎么做的exception? php.net的手册很混乱! // […]