a.hpp
file:
namespace hello
{
class A : public hi::B
public:
A(C* my_hello);
private:
const C* p_hello;
};
a.cpp
:
hello::A::A(C* my_hello)
: m_name(0);
{
}
In b.cpp
file:
hello::A *random = new hello::A();
//-> Error in this line saying no instance of constructor
How to instantiate the constructor when there is a pointer to a class in the parameter
In your .hpp file, you aren't defining a constructor for A, you typed hello(...)
instead.
Also, since you defined a constructor, your class doesn't have a default constructor anymore (ie one that doesn't need any arguments).
When calling the constructor of your class in the new expression, you must supply al needed arguments.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.