Simple Inheritance
-
I have a class ServiceResponse that inherits WebResponse. When I create a new ServiceResponse I want to set the base WebResponse with a variable that I pass to the Service Response constructor. How can I do this? I have this class structure:
public class ServiceResponse : WebResponse
{
public ServiceResponse(HttpWebResponse resp)
{
//how do I set the base WebResponse to resp?
}
}/\ |_ E X E GG
-
I have a class ServiceResponse that inherits WebResponse. When I create a new ServiceResponse I want to set the base WebResponse with a variable that I pass to the Service Response constructor. How can I do this? I have this class structure:
public class ServiceResponse : WebResponse
{
public ServiceResponse(HttpWebResponse resp)
{
//how do I set the base WebResponse to resp?
}
}/\ |_ E X E GG
public ServiceResponse(HttpWebResponse resp) : base(resp) { //how do I set the base WebResponse to resp? } this forces a base constructor that takes this parameter to be called. I'd be surprised if you need this code, I'd expect the base constructor to work, as in ServiceResponse sr = new ServiceResponse(resp); // I think this should call the base constructor for you but build the derived object )
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
I have a class ServiceResponse that inherits WebResponse. When I create a new ServiceResponse I want to set the base WebResponse with a variable that I pass to the Service Response constructor. How can I do this? I have this class structure:
public class ServiceResponse : WebResponse
{
public ServiceResponse(HttpWebResponse resp)
{
//how do I set the base WebResponse to resp?
}
}/\ |_ E X E GG
You can't do that. When the constructor is running, the object is already created, and you are in it. When you create an instance of an inherited class, there is just that instance. There is no separate base object. Perhaps you want to encapsulate an instance of the WebResponse class in your class, instead of inheriting from it.
--- single minded; short sighted; long gone;
-
You can't do that. When the constructor is running, the object is already created, and you are in it. When you create an instance of an inherited class, there is just that instance. There is no separate base object. Perhaps you want to encapsulate an instance of the WebResponse class in your class, instead of inheriting from it.
--- single minded; short sighted; long gone;
-
I have a class ServiceResponse that inherits WebResponse. When I create a new ServiceResponse I want to set the base WebResponse with a variable that I pass to the Service Response constructor. How can I do this? I have this class structure:
public class ServiceResponse : WebResponse
{
public ServiceResponse(HttpWebResponse resp)
{
//how do I set the base WebResponse to resp?
}
}/\ |_ E X E GG
Are you looking for something like this?
public class ServiceResponse : WebResponse
{
public ServiceResponse
(
HttpWebResponse resp
)
: base ( resp )
{
}
}