• Advertisement

Archived

This topic is now archived and is closed to further replies.

Annoying C++ Inheritance error

This topic is 5810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m writing a driver that will read data from a non-HID controller and emulate a HID device. When I compile my code using DriverWorks, I receive the following message. NTSTATUS XHidMiniDriver::AddDevice(PDEVICE_OBJECT Fdo) { NTSTATUS status; // This is the Erring line XHidDevice* p = new (NonPagedPool) XHidDevice(Fdo); if (p == NULL) status = STATUS_INSUFFICIENT_RESOURCES; else { status = p->ConstructorStatus(); if ( !NT_SUCCESS(status) ) delete p; } return status; } class XHidDevice : public KHidDevice { SAFE_DESTRUCTORS public: // Constructor; Part of problem XHidDevice(PDEVICE_OBJECT Fdo); NTSTATUS ReadReport(KIrp I); NTSTATUS DefaultHidRequestHandler(KIrp I); NTSTATUS DefaultPower(KIrp I); NTSTATUS DefaultPnp(KIrp I); }; For those who don''t know about DriverWorks, KHidDevice has no constructor with zero parameters. However, it does have a constructor that takes a PDEVICE_OBJECT. How do I get XHidDevice to call KHidDevice''s constructor? When I compile, I receive this message XHID\XHIDDevice.cpp(14) : error C2512: ''KHidDevice'' : no appropriate default constructor available

Share this post


Link to post
Share on other sites
Advertisement
in the implementation of the constructor (.cpp file probs)


XHidDevice::XHidDevice(PDEVICE_OBJECT Fdo): KHidDevice(Fdo) {

//whatever stuff you have in the constructor

}


-me

Share this post


Link to post
Share on other sites
Alright, I tried the suggestion, and now I get the following error:

XHID\XHIDDevice.cpp(14) : error C2664: ''__thiscall KHidDevice::KHidDevice(class KHidDevice &)'' : cannot convert parameter 1 from ''struct _DEVICE_OBJECT *'' to ''class KHidDevice &''
A reference that is not to ''const'' cannot be bound to a non-lvalue

I have no idea where it''s getting that constructor, seeing as how the constructor definition is

KHidDevice(
PDEVICE_OBJECT Fdo,
PHID_REPORT_DESCRIPTOR pReportDescriptor,
ULONG ReportLength,
PWCHAR DeviceID,
PWCHAR HardwareIDs,
PWCHAR CompatibleIDs,
PWCHAR InstanceID,
PHID_DEVICE_ATTRIBUTES pAttributes,
PHID_STRING_DESCRIPTOR pDeviceString,
ULONG DeviceStringSize,
UCHAR CountryCode=0
);

Share this post


Link to post
Share on other sites
wait, if the base class constructor expects ALL those parameters you have to pass ALL of those parameters in the : KHidDevice(....) call. you can't just pass one parameter if there is no existing KHidDevice constructor that only excepts one parameter.

i also don't know where it's getting that constructor but you are definitely confusing the compiler if you are trying to call a constructor with only one parameter that expects 11....

-me

[edited by - Palidine on May 30, 2002 6:12:48 PM]

Share this post


Link to post
Share on other sites

  • Advertisement