I'm trying to use some code that I downloaded from the internet and I'm having difficulties constructing objects that contain objects whose type is defined in the downloaded code.
For example, the downloaded code defines a "Factor" class with the following header file (I've deleted the parts of the code I think are relevant for brevity)
#ifndef __defined_libdai_factor_h
#define __defined_libdai_factor_h
namespace dai{
#include <iostream>
#include <functional>
#include <cmath>
#include <dai/prob.h>
#include <dai/varset.h>
#include <dai/index.h>
#include <dai/util.h>
template <typename T>
class TFactor {
private:
/// Stores the variables on which the factor depends
VarSet _vs;
/// Stores the factor values
TProb<T> _p;
public:
/// \name Constructors and destructors
//@{
/// Constructs factor depending on no variables with value \a p
TFactor ( T p = 1 ) : _vs(), _p(1,p) {}
/// Constructs factor depending on the variable \a v with uniform distribution
TFactor( const Var &v ) : _vs(v), _p(v.states()) {}
/// Constructs factor depending on variables in \a vars with uniform distribution
TFactor( const VarSet& vars ) : _vs(vars), _p((size_t)_vs.nrStates()) {
DAI_ASSERT( _vs.nrStates() <= std::numeric_limits<std::size_t>::max() );
}
/// Constructs factor depending on variables in \a vars with all values set to \a p
TFactor( const VarSet& vars, T p ) : _vs(vars), _p((size_t)_vs.nrStates(),p) {
DAI_ASSERT( _vs.nrStates() <= std::numeric_limits<std::size_t>::max() );
}
};
}
#endif
I've defined an class called "MDP_Model" that has the following header file
The actual definition of this constructor is in the .cpp file, which I omitted in my previous post. Here it is
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include "mdp_model.h"
usingnamespace std;
usingnamespace dai;
MDP_Model::MDP_Model(Factor R, Factor T, Factor P_S1){
/// set the rewards
_rewards.push_back(R);
/// set the transitions
_transitions.push_back(T);
/// Stores the initial state distribution
_initial_state_dist = P_S1;
}
I don't understand why this definition in the .cpp file isn't enough?