Object instance creation error

A

Ami

Hi All,
I am trying to create a class whose constructor takes Void
parameter and stores it for future reference. It works fine as
expected.

class base
{
public:
base(LPVOID pObj){ //store lpvoid for reference};
virtual ~base(){};
virtual void func1() { printf("Hello from base\n") };
};

When I create another class from above given class and try to create
object from it, it get following error.

error C2664: 'derived::derived' : cannot convert parameter 1 from
'const int' to 'const class derived &'
Reason: cannot convert from 'const int' to 'const class
derived'
No constructor could take the source type, or constructor
overload resolution was ambiguous


class derived:public base
{
protected:
virtual void func1(){ printf("Hello from Derived\n") };
};

int main()
{
base *nderived= new derived(NULL); //error
}


Please can any one help me to make this working.
Thanks and Regards
 
O

Obnoxious User

Hi All,
I am trying to create a class whose constructor takes Void
parameter and stores it for future reference. It works fine as
expected.

class base
{
public:
base(LPVOID pObj){ //store lpvoid for reference};
virtual ~base(){};
virtual void func1() { printf("Hello from base\n") };
};

When I create another class from above given class and try to create
object from it, it get following error.

error C2664: 'derived::derived' : cannot convert parameter 1 from
'const int' to 'const class derived &'
Reason: cannot convert from 'const int' to 'const class
derived'
No constructor could take the source type, or constructor
overload resolution was ambiguous


class derived:public base
{
protected:
virtual void func1(){ printf("Hello from Derived\n") };

public:
derived(LPVOID v) : base(v) {}
 
S

Senthil

Hi All,
I am trying to create a class whose constructor takes Void
parameter and stores it for future reference. It works fine as
expected.

class base
{
public:
base(LPVOID pObj){ //store lpvoid for reference};
virtual ~base(){};
virtual void func1() { printf("Hello from base\n") };

};

When I create another class from above given class and try to create
object from it, it get following error.

error C2664: 'derived::derived' : cannot convert parameter 1 from
'const int' to 'const class derived &'
Reason: cannot convert from 'const int' to 'const class
derived'
No constructor could take the source type, or constructor
overload resolution was ambiguous

class derived:public base
{
protected:
virtual void func1(){ printf("Hello from Derived\n") };

};

int main()
{
base *nderived= new derived(NULL); //error

}

Please can any one help me to make this working.
Thanks and Regards

Since the base class constrcutor needs a argument, you derived class'
constructor should provide it.
class derived : public base
{
derived(void*):base(NULL){}
}

would make your code compile..

Best Regards,
Senthil
 
S

Stefan Naewe

Hi All,
I am trying to create a class whose constructor takes Void
parameter and stores it for future reference. It works fine as
expected.

class base
{
public:
base(LPVOID pObj){ //store lpvoid for reference};
virtual ~base(){};
virtual void func1() { printf("Hello from base\n") };
};

When I create another class from above given class and try to create
object from it, it get following error.

error C2664: 'derived::derived' : cannot convert parameter 1 from
'const int' to 'const class derived &'
Reason: cannot convert from 'const int' to 'const class
derived'
No constructor could take the source type, or constructor
overload resolution was ambiguous


class derived:public base
{
protected:
virtual void func1(){ printf("Hello from Derived\n") };
};

int main()
{
base *nderived= new derived(NULL); //error
}


Please can any one help me to make this working.
Thanks and Regards

derived does not have a c'tor that's able to take 'NULL'.
You have to declare that c'tor in class derived.

Regards,
Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,798
Messages
2,569,651
Members
45,384
Latest member
GOLDY

Latest Threads

Top