Can't find a certain constructor.

Hi,

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)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef mdp_model_h
#define mdp_model_h


#include <dai/factor.h>


class MDP_Model {
    private:
        /// Stores the rewards
        std::vector<dai::Factor> _rewards;
	/// Stores the transitions
        std::vector<dai::Factor> _transitions;
        /// Stores the initial state distribution
        dai::Factor _initial_state_dist;

    public:
    /// \name Constructors and destructors
    //@{
        /// Default constructor
        MDP_Model() : _rewards(), _transitions(), _initial_state_dist() {}

        /// Constructs a factor graph from a vector of factors
        MDP_Model(dai::Factor, dai::Factor, dai::Factor);
	
        /// Destructor
        virtual ~MDP_Model() {}

        /// Virtual copy constructor
        virtual MDP_Model* clone() const { return new MDP_Model(*this); }
    //@}
};

#endif 


where I've defined the relevant functions in the corresponding .cpp file. Now when I try to construct a MDP_Model using the second constructor, e.g.
1
2
3
4
5
6
7
8
MDP_Model initialise_chain_problem_MDP() {
  
    Factor P_S1, P_S2_given_S1_A1, R_given_S2_A2;
    
    MDP_Model chain_mdp_model(P_S1, P_S2_given_S1_A1, R_given_S2_A2);
    
    return chain_mdp_model;
}


I get the following error



initialise_chain_problem.cpp:(.text+0x5c0): undefined reference to `MDP_Model::MDP_Model(dai::TFactor<double>, dai::TFactor<double>, dai::TFactor<double>)'



What am I missing here?

TAI
Line 24 of the second file:

MDP_Model(dai::Factor, dai::Factor, dai::Factor);

This has no definition.
Thanks for the response.

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"

using namespace std;
using namespace 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?
Doh,

Just realised that I wasn't linking my files properly.

Sorry.
Topic archived. No new replies allowed.