Base Class Doesn't Contain Parameterless Constructor?
http://stackoverflow.com/questions/7689742/base-class-doesnt-contain-parameterless-constructor
#region Assembly System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Data.Entity.dll
#endregion
ObjectContext类所处的命名空间System.Data.Objects
public partial class DB_COMAPEntities : ObjectContext
{
}
上面的类,无法通过编译,提示说,父类(ObjectContext)没有无参构造函数
DB_COMAPEntities 子类默认有一个无参构造函数,这个默认的无参构造函数去调用父类的无参构造函数。
而父类ObjectContext恰好没有无参构造函数,所以出错了。
解决方法:
显示指定调用的父类的有参构造函数,传递给父类有参构造函数的参数,是写死的常量。
public partial class DB_COMAPEntities : ObjectContext
{
public DB_COMAPEntities() : base("name=DB_COMAPEntities", "DB_COMAPEntities")
{ }
}
http://stackoverflow.com/questions/7689742/base-class-doesnt-contain-parameterless-constructor
class A
{
public A(int x, int y)
{
// do something
}
} class A2 : A
{
public A2() : base(, )
{
// do something
} public A2(int x, int y) : base(x, y)
{
// do something
} // This would not compile:
public A2(int x, int y)
{
// the compiler will look for a constructor A(), which doesn't exist
}
}
In class A2, you need to make sure that all your constructors call the base class constructor with parameters.
Otherwise, the compiler will assume you want to use the parameterless base class constructor to construct the A object on which your A2 object is based.
总结:
在父类没有无参构造函数的时候,子类的构造函数,必须显示指定如何调用父类的有参构造函数
Base Class Doesn't Contain Parameterless Constructor?的更多相关文章
- AddDbContext was called with configuration, but the context type 'NewsContext' only declares a parameterless constructor?
问题 An error occurred while starting the application. ArgumentException: AddDbContext was called with ...
- AddDbContext was called with configuration, but the context type 'MyDBContext' only declares a parameterless constructor
System.ArgumentException HResult=0x80070057 Message=AddDbContext was called with configuration, but ...
- Base class does not contain a constructor that takes '0' argument
刚刚在写一段直播室网站中的一段程序遇,突然遇到一个错误,如下 'TVLLKBLL.BaseClass' does not contain a constructor that takes 0 argu ...
- no parameterless constructor define for type 解决一例
在生成根据模型和上下文生成带增删查改操作的视图的控制器时,提示上述信息,网上查找了资料也没有解决,突然想起该项目是连接MSSQL数据库和Redis数据库的,并且已经依赖注入了,而Redis数据库的服务 ...
- [Java Basics] Stack, Heap, Constructor, I/O, Immutable, ClassLoader
Good about Java: friendly syntax, memory management[GC can collect unreferenced memory resources], o ...
- Virtual member call in a constructor
http://stackoverflow.com/questions/119506/virtual-member-call-in-a-constructor (Assuming you're writ ...
- Es6 类的关键 super、static、constructor、new.target
ES6引入了Class(类)这个概念,作为对象的模板,通过class关键字,可以定义类.基本上,ES6的class可以看作只是一个语法糖,它的绝大部分功能,ES5都可以做到,新的class写法只是让对 ...
- copy constructor
copy constructor也分为trivial和nontrivial两种 如果class展现出bitwise copy semantics(按位拷贝语义),则不会构造出 copy constru ...
- Es6 类class的关键 super、static、constructor、new.target
ES6引入了Class(类)这个概念,作为对象的模板,通过class关键字,可以定义类.基本上,ES6的class可以看作只是一个语法糖,它的绝大部分功能,ES5都可以做到,新的class写法只是让对 ...
随机推荐
- [Android]异常10-java.lang.OutOfMemoryError pthread_create (1040KB stack) failed: Try again
背景:应用正常运行一段时间后,创建线程时出现应用重启,停止运行 异常原因: 可能一>堆内存溢出 解决办法有: 解决一>创建线程池,短时间能执行完成线程放在其中.(常驻线程例外),注意线程的 ...
- HDU_1113_字符串处理
Word Amalgamation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- mysql_基础1
初学mysql,感觉挺有意思的. mysql指令的一些参数: promrt修改提示符: PROMPT \D mysql的语法规范: 一些函数: 创建数据库: SHOW CREATE DATABAS ...
- The Standard SSL Handshake
The following is a standard SSL handshake when RSA key exchange algorithm is used: 1. Client Hello ...
- privot函数使用
语法: table_source PIVOT( 聚合函数(value_column) FOR pivot_column IN(<column_list>) ) 将列转化为行 写个小示例 : ...
- swap() 函数实现的方法
swap()函数总结: 一.利用临时变量 1.引用(交换任意类型) template <typename T> void swap(T& x,T& y) { T tmp; ...
- 【JAVA】简陋的学生信息管理系统
因为之前写了一个学生信息管理系统,但还是处于命令行界面,不美观,于是打算做一个完整的界面出来. 在网上查阅资料后发现C++本身是不支持图形化界面的(可以使用第三方的Qt来做) 权衡之下还是选择了JAV ...
- 18.match_phrase的用法
主要知识点: match_phrase的使用场景 match_phrase的用法 match_phrase的原理 一.什么是近似匹配 match_phrase的使用场景 现假设有两个句子 ...
- elisp 编程 if 特殊表
elisp中的 if 特殊表与其他语言中的 if 语句逻辑上并无二致,关键在于如何使用. (if (> 4 3) (message "4 is greater than 3" ...
- OSI七层参考模型每一层都有哪些协议
OSI七层参考模型每一层都有哪些协议 第七层应用层 协议:DHCP • DNS • FTP • Gopher • HTTP • IMAP4 • IRC • NNTP • XMPP • POP3 • S ...