自适应网站用什么软件设计,移动应用开发技术有哪些,hph网站模板,做平面什么网站好用这个问题是在写观察者模式中遇到的一个问题。
具体的代码可以到《设计模式#xff08;十五#xff09;之观察者模式》中下载#xff0c;下边只是部分代码。 我在抽象类中定义了构造函数#xff0c;代码如下#xff1a;
using System;
using System.Collections.Generic;… 这个问题是在写观察者模式中遇到的一个问题。
具体的代码可以到《设计模式十五之观察者模式》中下载下边只是部分代码。 我在抽象类中定义了构造函数代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace Observer
{/// summary/// 博客抽象类有订阅功能/// /summarypublic abstract class blog{/// summary/// 订阅者列表/// /summarypublic ListIObserver observerList new ListIObserver();/// summary/// 博客标题/// /summarypublic string blogTitle ;/// summary/// 博客作者/// /summarypublic string blogAuthor ;/// summary/// 构造函数/// /summary/// param nametitle博客标题/param/// param nameauthor博客作者/parampublic blog(string title,string author){this.blogAuthor author;this.blogTitle title;}}
} 大家注意我这个构造函数中是有参数的。
接下来我写了一个类来继承他最开始我是这样写的
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace Observer
{public class MyBlog : blog{public MyBlog(string title,string author){}}
}
报错; 去网上找了一下得到的结果基本上都是:
父类有了带参数的构造函数子类的构造函数可以不和父类的构造函数一样但是如果你的父类定义了带参数的构造函数同时没有无参重载的情况下那么在子类中你必须对父类的带参数的构造进行赋值也就是实参
代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace Observer
{public class MyBlog : blog{public MyBlog(string title,string author) : base(title,author){}}
} 解决方法就是在子类的构造函数后加上base关键字及对应父类构造函数需要的参数。 以上就是所有的解决方法。
有好的建议请在下方输入的评论。