|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Overridable variable members?internal structures to define the underlying data structure for a class. This class is then used as a base class for other derived classes. I've worked out how to get initialized structure variables in classes, but the problem is I cannot work out how to override the variable in derived classes. I keep getting 'virtual'/'override' not valid for item & "'new' must be used here" errors. Is there anyway to do this? I realise that I can create a virtual function that can be called to init the variable, but the structures used are pretty large & complex and the extra time used to construct the init data at runtime is horrific (extra few seconds at startup), so I'd rather just nut this out. Sample Code: public abstract class Base { protected internal struct BaseData { public string SomeVariable; public BaseData(string s) { SomeVariable = s; } } protected internal BaseData initData; } public class Derived { protected internal BaseData initData = new BaseData("Derived Class Init Data"); } How can I do this? >Is there anyway to do this? Can't you just pass it to a base class constructor?public abstract class Base { protected Base(BaseData init) { initData = init; } protected internal BaseData initData; } public class Derived : Base { public Derived() : base(new BaseData("Derived Class Init Data")) {} } Mattias -- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup.
Other interesting topics
garbage collection problem in large linked list
Copy protection for a .NET application Is there anyway to treat ViewState the same as SessionState? .Net assemblies decompilers Assemblies Working Set .Net Framework in Windows 2003 asp.net newbie Setup of a .NET Installation XML editor component Hide Directory programmatically |
|||||||||||||||||||||||