3 Replies - 505 Views - Last Post: 11 February 2014 - 06:45 AM Rate Topic: -----

#1 ekiim   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 31-March 13

"returning" a vector

Posted 10 February 2014 - 10:25 PM

Hello, i have a little issue, and i am not sure what is the problem, i tried to make a function that returns a vector of bools, but it seams i cannot make that function so, i made a function type void that works with the pointers of 3 vectors, and i dont get where is the problem, the compiler (code blocks) says that its something with
error: request for member ‘at’ in ‘uno’, which is of pointer type ‘std::vector<bool>*’ (maybe you meant to use ‘->’ ?)
but i dont seem to spot the problem,
any help, (if you can help me to make the function that receives the 2 vectors and retunrs the thirds would bee even better...
(i am trying to simulate the binary sum behavior)
(i am not that well familiar with the object syntax, that is why y try to use the vector class to do it, i think that could be part of the problem)

any help?

// uno = first operand
// dos = second operand
// resp = the "returning" vector with the result
// temp = the temporal to make the count of the sum
// res = a variable in case i need to work with it before passing it into resp
void sum(std::vector<bool>*uno, std::vector<bool>*dos, std::vector<bool>*resp){
    std::vector <bool> res(0,64);
    std::vector <bool> temp(0,64);

    for(int i=0;i<64;i++){

    for(int i=0; i<64;i++){
            res[i]=(uno[i]||dos[i])? true:false;


Is This A Good Question/Topic? 0
  • +

Replies To: "returning" a vector

#2 jjl   User is offline

  • Engineer
  • member icon

Reputation: 1270
  • View blog
  • Posts: 4,998
  • Joined: 09-June 09

Re: "returning" a vector

Posted 10 February 2014 - 10:47 PM

You cant just declare a pointer and start using it. You need to give them memory to point to.
Was This Post Helpful? 0
  • +
  • -

#3 #define   User is offline

  • Duke of Err
  • member icon

Reputation: 1853
  • View blog
  • Posts: 6,671
  • Joined: 19-February 09

Re: "returning" a vector

Posted 10 February 2014 - 11:07 PM

Hi, instead of a pointer a reference parameter may be simpler.

Hopefully something like this would work:

void sum( const vector<bool> &uno, 
          const vector<bool> &dos,
                vector<bool> &resp )

  resp[0] = uno[0] && dos[0];

Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3795
  • View blog
  • Posts: 13,738
  • Joined: 08-August 08

Re: "returning" a vector

Posted 11 February 2014 - 06:45 AM

Technically you're not trying to return a vector since your function is void, meaning that it does not return anything. The valid solution #define provides references the vectors passed to it and alters the values of the third reference. It does not return any vector.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1