Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old May 23rd, 2006, 05:15 PM
schdvir@gmail.com
Guest
 
Posts: n/a
Default help please

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<float, std::allocator<float> >[color=blue]
>)[/color]

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

  #2  
Old May 23rd, 2006, 05:35 PM
Howard
Guest
 
Posts: n/a
Default Re: help please


<schdvir@gmail.com> wrote in message
news:1148400451.973985.289160@i40g2000cwc.googlegr oups.com...[color=blue]
> 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<float, std::allocator<float> >[color=green]
>>)[/color]
>
> 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
>[/color]

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




  #3  
Old May 23rd, 2006, 05:35 PM
Luke Meyers
Guest
 
Posts: n/a
Default Re: help please

schdvir@gmail.com wrote:[color=blue]
> 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<float, std::allocator<float> >[color=green]
> >)[/color][/color]

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.
[color=blue]
> tdagent.C
> -------------------
>
> #include "tdagent.H"
>
> tdagent::tdagent(simple_env* environment)
> {[/color]

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.
[color=blue]
> actor1 = new actor(env->get_cov);[/color]

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?
[color=blue]
> actro.H
> -------------
>
> using namespace boost::numeric::ublas;[/color]

Never do this in headers.

Luke

  #4  
Old May 23rd, 2006, 05:45 PM
Daniel T.
Guest
 
Posts: n/a
Default Re: help please

In article <1148400451.973985.289160@i40g2000cwc.googlegroups .com>,
schdvir@gmail.com wrote:
[color=blue]
> 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<float, std::allocator<float> >[color=green]
> >)[/color]
>
> 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.[/color]

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;
//...
};
  #5  
Old May 23rd, 2006, 06:15 PM
Marcus Kwok
Guest
 
Posts: n/a
Default Re: help please

schdvir@gmail.com wrote:[color=blue]
> 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<float, std::allocator<float> >[color=green]
>>)[/color]
>
> 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
> -------------[/color]
[snip][color=blue]
> 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.[/color]

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.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
  #6  
Old May 25th, 2006, 09:05 AM
schdvir@gmail.com
Guest
 
Posts: n/a
Default Re: help please

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

  #7  
Old May 25th, 2006, 03:05 PM
Marcus Kwok
Guest
 
Posts: n/a
Default Re: help please

schdvir@gmail.com wrote:[color=blue]
> tdagent.H
> --------------------
> typedef struct state_t
> {
> float current;
> float prev;
> float reward;
> } state;[/color]

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

struct state {
float current;
float prev;
float reward;
};
[color=blue]
> 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())[/color]

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).
[color=blue]
> {
> 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?[/color]

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

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
  #8  
Old May 25th, 2006, 03:35 PM
Howard
Guest
 
Posts: n/a
Default Re: help please


<schdvir@gmail.com> wrote in message
news:1148543932.696511.149480@j33g2000cwa.googlegr oups.com...[color=blue]
> 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[/color]
What's that second set of include guards for???
[color=blue]
>
> typedef struct state_t
> {
> float current;
> float prev;
> float reward;
> } state;[/color]
Just use:

struct state{
....whatever...
};
[color=blue]
> #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())[/color]
The member name is "actor1", not "actor".
[color=blue]
> : critic(new critic(env->get_cov())[/color]
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.
[color=blue]
> {
> float d;
> state x;[/color]
What are those used for?
[color=blue]
> //vector<float> u(2);
> env=environment;
> //actor1 = new actor(env->get_cov());[/color]
That should be fine now, since you added the ().
[color=blue]
> //actor2 = new actor(env->get_cov);
> //critic1 = new critic(env->get_cov());[/color]
Same here.
[color=blue]
> }
>
> tdagent::~tdagent()
> {
> delete actor;
> delete critic;[/color]
These shoud be "actor1" and critic1". You delete the object by the
pointer's name, not by the class name.
[color=blue]
> 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'[/color]
That one's because you used "actor" instead of "actor1". (The rest might go
away once you fix or remove that.)
[color=blue]
> 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[/color]
I didn't count the lines, but I suspect these are the errors on the "delete"
statements I mentioned above.

-Howard



 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,338 network members.