help please

S

schdvir

Hi
I tried to compile a program and I got this error:

tdagent.C: In constructor `tdagent::tdagent(simple_env*)':
tdagent.C:13: error: no matching function for call to `actor::actor()'
actor.H:28: note: candidates are: actor::actor(const actor&)
actor.H:38: note: actor::actor(boost::numeric::ublas::vector<float,
boost::numeric::ublas::unbounded_array said:

the code is:

tdagent.C
-------------------

#include "tdagent.H"

tdagent::tdagent(simple_env* environment)
{
float d;
state x;
//vector<float> u(2);
env=environment;
actor1 = new actor(env->get_cov);
//actor2 = new actor(env->get_cov);
critic1 = new critic(env->get_cov);
}


actro.H
-------------

#ifndef ACTOR_H
#define ACTOR_H


#include "weights.H"
#include "base_functions.H"
#include <boost/random.hpp>

namespace ublas = boost::numeric::ublas;
using namespace boost::numeric::ublas;


#define ETA_ACTOR 1
#define A_MIN_ACTOR 1
#define E_MAX_ACTOR 1
#define C 1


class actor
{

private:

float function(ublas::vector<float> x);
float f;
float u;


public:
actor(ublas::vector<float> const covariance);
~actor();
bool preform_step();
float action(ublas::vector<float> x);


};

#endif


I don't understand the error because line 13 at tdagent.C is the first
line of the costructor (right after the "{" )
there isn't a call for actor::actor() there.

Hope you can help me with it.

Thanks
Dvir
 
H

Howard

Hi
I tried to compile a program and I got this error:

tdagent.C: In constructor `tdagent::tdagent(simple_env*)':
tdagent.C:13: error: no matching function for call to `actor::actor()'
actor.H:28: note: candidates are: actor::actor(const actor&)
actor.H:38: note: actor::actor(boost::numeric::ublas::vector<float,


the code is:

tdagent.C
-------------------

#include "tdagent.H"

tdagent::tdagent(simple_env* environment)
{
float d;
state x;
//vector<float> u(2);
env=environment;
actor1 = new actor(env->get_cov);
//actor2 = new actor(env->get_cov);
critic1 = new critic(env->get_cov);
}


actro.H
-------------

#ifndef ACTOR_H
#define ACTOR_H


#include "weights.H"
#include "base_functions.H"
#include <boost/random.hpp>

namespace ublas = boost::numeric::ublas;
using namespace boost::numeric::ublas;


#define ETA_ACTOR 1
#define A_MIN_ACTOR 1
#define E_MAX_ACTOR 1
#define C 1


class actor
{

private:

float function(ublas::vector<float> x);
float f;
float u;


public:
actor(ublas::vector<float> const covariance);
~actor();
bool preform_step();
float action(ublas::vector<float> x);


};

#endif

What's the definition of tdagent? Perhaps the answer lies there.

Also, what's "get_cov"? Is that a function? If so, you've left out the
parentheses. Perhaps that's causing the initial error, and the error you've
shown above is caused by the compiler not being able to resolve the
constructor properly because of that?

-Howard
 
L

Luke Meyers

tdagent.C: In constructor `tdagent::tdagent(simple_env*)':
tdagent.C:13: error: no matching function for call to `actor::actor()'
actor.H:28: note: candidates are: actor::actor(const actor&)
actor.H:38: note: actor::actor(boost::numeric::ublas::vector<float,

This means that something is trying to call the default constructor for
actor, but the default constructor doesn't exist. Normally, the
compiler generates one for you -- however, if you create any other
constructors (except copy ctor? Can't recall ATM), it won't do that so
you have to create one yourself.

Unfortunately, you didn't post tdagent.H, so we don't have enough code
here to figure out where you're doing this. Most likely you have an
actor as a data member of tdagent, and since you didn't use an
initializer list (learn about those, they're important), it gets
default-constructed prior to entering the constructor body.
tdagent.C
-------------------

#include "tdagent.H"

tdagent::tdagent(simple_env* environment)
{

At this point, any data members (other than primitives) you haven't
initialized via an initializer list will be default-initialized, which
means they need a zero-arg (nullary) ctor.
actor1 = new actor(env->get_cov);

Now, I wonder very much why you'd have an actor as a by-value data
member of tdagent, if you've got other actors by-pointer.

Where's the destructor?

Never do this in headers.

Luke
 
D

Daniel T.

Hi
I tried to compile a program and I got this error:

tdagent.C: In constructor `tdagent::tdagent(simple_env*)':
tdagent.C:13: error: no matching function for call to `actor::actor()'
actor.H:28: note: candidates are: actor::actor(const actor&)
actor.H:38: note: actor::actor(boost::numeric::ublas::vector<float,


the code is:

tdagent.C
-------------------

#include "tdagent.H"

tdagent::tdagent(simple_env* environment)
{
float d;
state x;
//vector<float> u(2);
env=environment;
actor1 = new actor(env->get_cov);
//actor2 = new actor(env->get_cov);
critic1 = new critic(env->get_cov);
}


I don't understand the error because line 13 at tdagent.C is the first
line of the costructor (right after the "{" )
there isn't a call for actor::actor() there.

Your tdagent class contains an actor object by value. Either remove
that, or initialize it before the '{'.

See:
<http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.6>


I have a feeling you are coming from Java and don't realize that you
have declared 'actor1' by value rather than by pointer. Try this:

class tdagent {
actor* actor1;
//...
};
 
M

Marcus Kwok

Hi
I tried to compile a program and I got this error:

tdagent.C: In constructor `tdagent::tdagent(simple_env*)':
tdagent.C:13: error: no matching function for call to `actor::actor()'
actor.H:28: note: candidates are: actor::actor(const actor&)
actor.H:38: note: actor::actor(boost::numeric::ublas::vector<float,
boost::numeric::ublas::unbounded_array said:

the code is:

tdagent.C
-------------------

#include "tdagent.H"

tdagent::tdagent(simple_env* environment)
{
float d;
state x;
//vector<float> u(2);
env=environment;
actor1 = new actor(env->get_cov);
//actor2 = new actor(env->get_cov);
critic1 = new critic(env->get_cov);
}


actro.H
------------- [snip]
class actor
{
public:
actor(ublas::vector<float> const covariance);
~actor();
bool preform_step();
float action(ublas::vector<float> x);
};

I don't understand the error because line 13 at tdagent.C is the first
line of the costructor (right after the "{" )
there isn't a call for actor::actor() there.

Is tdagent derived from actor? If so, then there is an implicit call to
the base class constructor. For example:

tdagent::tdagent(simple_env* environment)
: actor() // <--- this call is implicit unless you specify otherwise
{
// ...
}

which you can change to:

tdagent::tdagent(simple_env* environment)
: actor(environment->get_cov)
{
// ...
}

assuming that this is what is happening and that you will insert
appropriate checks that e.g. environment is not null.
 
S

schdvir

Hi

first of all thanks for your help. Now, here is the header;

tdagent.H
--------------------

#ifndef TDGAENT_H
#define TDAGENT_H

#ifndef STATE
#define STATE

typedef struct state_t
{
float current;
float prev;
float reward;
} state;




#include "critic.H"
#include "actor.H"
#include "simple_env.H"


//namespace ublas = boost::numeric::ublas;
//using namespace boost::numeric::ublas;



class tdagent
{

private:

float get_state();
float get_previous_state();
void set_previous_state(float curr_state);
float get_reward();
simple_env* env;
actor* actor1;
critic* critic1;



public:
tdagent(simple_env* environment);
~tdagent();
float find_next_action();


};

#endif
#endif


I tried to initiliaze the class actor using an Initialization list.
now the constructor and destructor are these:

tdagent.C
----------------
#include "tdagent.H"

tdagent::tdagent(simple_env* environment)
: actor(new actor(env->get_cov())
: critic(new critic(env->get_cov())

{
float d;
state x;
//vector<float> u(2);
env=environment;
//actor1 = new actor(env->get_cov());
//actor2 = new actor(env->get_cov);
//critic1 = new critic(env->get_cov());
}

tdagent::~tdagent()
{
delete actor;
delete critic;
return;

}


and now I get the following error:

tdagent.C: In constructor `tdagent::tdagent(simple_env*)':
tdagent.C:13: error: type `class actor' is not a direct base of
`tdagent'
tdagent.C:14: error: expected `{' before ':' token
tdagent.C: At global scope:
tdagent.C:14: error: expected unqualified-id before ':' token
tdagent.C:14: error: expected `,' or `;' before ':' token
tdagent.C: In destructor `tdagent::~tdagent()':
tdagent.C:28: error: expected primary-expression before ';' token
tdagent.C:29: error: expected primary-expression before ';' token

I guess my mistake is pretty basic, but as you probably see I'm new
with C++.

P.S.
Where should i use

using namespace boost::numeric::ublas;

If I'm using this this namespace at the header?

Thanks, again
Dvir
 
M

Marcus Kwok

tdagent.H
--------------------
typedef struct state_t
{
float current;
float prev;
float reward;
} state;

This is a C-ism that is no longer needed in C++. You can just do:

struct state {
float current;
float prev;
float reward;
};
class tdagent
{

private:

float get_state();
float get_previous_state();
void set_previous_state(float curr_state);
float get_reward();
simple_env* env;
actor* actor1;
critic* critic1;



public:
tdagent(simple_env* environment);
~tdagent();
float find_next_action();


};

I tried to initiliaze the class actor using an Initialization list.
now the constructor and destructor are these:

tdagent.C
----------------
#include "tdagent.H"

tdagent::tdagent(simple_env* environment)
: actor(new actor(env->get_cov())
: critic(new critic(env->get_cov())

If you are initializing more than one thing, then you use commas to
separate them, not colons:

tdagent::tdagent(simple_env* environment)
: actor(new actor(environment->get_cov())
, critic(new critic(environment->get_cov())

and also note that "env" has not been set yet at this point
(initialization list stuff happens before the body of the constructor is
executed).
{
float d;
state x;
//vector<float> u(2);
env=environment;
//actor1 = new actor(env->get_cov());
//actor2 = new actor(env->get_cov);
//critic1 = new critic(env->get_cov());
}

tdagent::~tdagent()
{
delete actor;
delete critic;
return;

}

P.S.
Where should i use

using namespace boost::numeric::ublas;

If I'm using this this namespace at the header?

My preference is to fully qualify the names in the header, and only use
"using namespace whatever" in the implementation file.
 
H

Howard

Hi

first of all thanks for your help. Now, here is the header;

tdagent.H
--------------------

#ifndef TDGAENT_H
#define TDAGENT_H

#ifndef STATE
#define STATE
What's that second set of include guards for???
typedef struct state_t
{
float current;
float prev;
float reward;
} state;
Just use:

struct state{
....whatever...
};
#include "critic.H"
#include "actor.H"
#include "simple_env.H"

//namespace ublas = boost::numeric::ublas;
//using namespace boost::numeric::ublas;

class tdagent
{
private:

float get_state();
float get_previous_state();
void set_previous_state(float curr_state);
float get_reward();
simple_env* env;
actor* actor1;
critic* critic1;

public:
tdagent(simple_env* environment);
~tdagent();
float find_next_action();
};

#endif
#endif

I tried to initiliaze the class actor using an Initialization list.
now the constructor and destructor are these:

tdagent.C
----------------
#include "tdagent.H"

tdagent::tdagent(simple_env* environment)
: actor(new actor(env->get_cov())
The member name is "actor1", not "actor".
: critic(new critic(env->get_cov())
Likewise, this member is "critic1", not "critic".
And in both cases, "env" has not been initialized yet. Perhaps you meant to
use "simple_env"?

I've never used "new" in an initialization list. There's nothing wrong with
putting those in the constructor body.

I'm still supsecting your only problem was that you left off the parentheses
on the calls to get_cov() below. Try going back to the way you had that
constructor (without the initialization list), with just those parentheses
added.

Here's how I'd do the initialization list here:

: env(environment), actor1(NULL), critic1(NULL)

Then I'd do the assignments in the constructor body.
{
float d;
state x;
What are those used for?
//vector<float> u(2);
env=environment;
//actor1 = new actor(env->get_cov());
That should be fine now, since you added the ().
//actor2 = new actor(env->get_cov);
//critic1 = new critic(env->get_cov());
Same here.
}

tdagent::~tdagent()
{
delete actor;
delete critic;
These shoud be "actor1" and critic1". You delete the object by the
pointer's name, not by the class name.
return;

}


and now I get the following error:

tdagent.C: In constructor `tdagent::tdagent(simple_env*)':
tdagent.C:13: error: type `class actor' is not a direct base of
`tdagent'
That one's because you used "actor" instead of "actor1". (The rest might go
away once you fix or remove that.)
tdagent.C:14: error: expected `{' before ':' token
tdagent.C: At global scope:
tdagent.C:14: error: expected unqualified-id before ':' token
tdagent.C:14: error: expected `,' or `;' before ':' token
tdagent.C: In destructor `tdagent::~tdagent()':
tdagent.C:28: error: expected primary-expression before ';' token
tdagent.C:29: error: expected primary-expression before ';' token
I didn't count the lines, but I suspect these are the errors on the "delete"
statements I mentioned above.

-Howard
 

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

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,282
Latest member
RoseannaBa

Latest Threads

Top