我有以下代码,我收到了这些错误:
public class SampleObjectPool extends GenericObjectPool {
private final static Log log = LogFactory.getLog(SampleObjectPool.class);
/**
* Constructor
* @param factory
*/
public SampleObjectPool(PoolableObjectFactory factory) {
super(factory);
log.debug("New pool created with factory ...");
}
/**
* Constructor
* @param factory
* @param config
*/
public SampleObjectPool(PoolableObjectFactory factory, Config config) {
super(factory, config);
log.debug("New pool created with factory and config ...");
}
/* (non-Javadoc)
* @see org.apache.commons.pool.ObjectPool#addObject()
*/
public void addObject() throws Exception {
log.debug("Add an object ...");
super.addObject();
}
/* (non-Javadoc)
* @see org.apache.commons.pool.ObjectPool#borrowObject()
*/
public Object borrowObject() throws Exception {
log.debug("Borrow an object ...");
return super.borrowObject();
}
/* (non-Javadoc)
* @see org.apache.commons.pool.ObjectPool#invalidateObject(java.lang.Object)
*/
public void invalidateObject(Object obj) throws Exception {
log.debug("Invalidate an object ...");
super.invalidateObject(obj);
}
/* (non-Javadoc)
* @see org.apache.commons.pool.ObjectPool#returnObject(java.lang.Object)
*/
public void returnObject(Object obj) throws Exception {
log.debug("Return an object ...");
super.returnObject(obj);
}
}
unique_int.hpp
"/tmp/ccymmVdG.o: In function `main':
1main.cpp:(.text+0x30): undefined reference to `unique_int_ptr::unique_int_ptr(int*)"
unique_int_ptr.hpp
#ifndef UNIQUE_PTR_HPP_INCLUDED
#define UNIQUE_PTR_HPP_INCLUDED
#include <typeinfo>
template<class Template> class unique_ptr
{
public:
unique_ptr(Template* ptr);
~ unique_ptr();
Template* get();
Template* operator->();
Template& operator*();
private:
Template* m_ptr;
/* unique_ptr(unique_ptr<Template> const&);
unique_ptr& operator=(const unique_ptr&);*/
};
#endif /* UNIQUE_PTR_HPP_INCLUDED */
unique_ptr.cpp
#ifndef UNIQUE_PTR_INT_HPP_INCLUDED
#define UNIQUE_PTR_INT_HPP_INCLUDED
class unique_int_ptr
{
public:
int* get();
unique_int_ptr (int* data);
~unique_int_ptr ();
private:
int* m_ptr;
};
#endif //UNIQUE_PTR_INT_HPP_INCLUDED
unique_int_ptr.cpp
#include <stdio.h>
#include "unique_ptr.hpp"
template<typename Template>
unique_ptr<Template>::unique_ptr(Template* ptr)
{
m_ptr = ptr;
}
template<typename Template>
unique_ptr<Template>::~unique_ptr()
{
delete m_ptr;
}
template<typename Template>
Template* unique_ptr<Template>::get()
{
return m_ptr;
}
template<typename Template>
Template* unique_ptr<Template>:: operator ->()
{
return m_ptr;
}
template<typename Template>
Template& unique_ptr<Template>::operator *()
{
return *m_ptr;
}
1main.cpp
#include "unique_int_ptr.hpp"
#include <stdio.h>
unique_int_ptr::unique_int_ptr (int* data)
{
m_ptr = new int;
m_ptr = data;
}
unique_int_ptr::~unique_int_ptr()
{
delete m_ptr;
}
int* unique_int_ptr::get ()
{
return m_ptr;
}
你知道我为什么会收到这个错误吗?此错误多次出现。我查看了有关模板的其他示例,但它不起作用。