5 Replies - 403 Views - Last Post: 05 January 2012 - 06:12 PM Rate Topic: -----

#1 jorakman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-January 12

obtain a value from a void function

Posted 03 January 2012 - 09:41 AM

Good day. I hope to get some suggestion, idea and guideline. Hope that you all can give some clue and idea.

let say in a.cpp, i have a function named void insert (.....). The function void insert (.....) is a virtual function.

Inside the void insert function in a.cpp, another function is called, also named void insert (.........). This function is located at b.cpp

Inside the void insert (.....) in b.cpp, there is one value known as InsertTime, which is the one i want collect.

I want to collect InsertTime value, pass the value to a new variable in void insert (.........) at a.cpp to do some calculation.

Can i know what should i do?

Sorry if my description is not clear.

Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: obtain a value from a void function

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,657
  • Joined: 23-August 08

Re: obtain a value from a void function

Posted 03 January 2012 - 09:46 AM

Read the function tutorials in my signature.
Was This Post Helpful? 0
  • +
  • -

#3 witchbanger  Icon User is offline

  • New D.I.C Head

Reputation: -45
  • View blog
  • Posts: 36
  • Joined: 04-December 11

Re: obtain a value from a void function

Posted 05 January 2012 - 03:10 PM

2 source files.
1 function each named insert.
one is void, the other is virtual void.

You want to pass a value from one void function to another void function.

Is that basically it?

First off, even though you have 2 source files, I don't thing you can have two functions named 'insert' of type void, even if one is virtual. I could be wrong, but have never seen that. It'd confuse the hell out of me. Assuming it is allowed, and I am wrong there, I would use a couple of pointers.

CPP file B, function

virtual void insert(){
do stuff;
make pointer;
assign a value to that pointer;
}


CPP file A function

void insert(){
read pointer;
get value;
use value;
}



That would be my guess. On a side note, while you are learning C++, take a course in grammar.
Was This Post Helpful? 0
  • +
  • -

#4 WabiSabi  Icon User is offline

  • D.I.C Head

Reputation: 51
  • View blog
  • Posts: 202
  • Joined: 31-December 10

Re: obtain a value from a void function

Posted 05 January 2012 - 03:55 PM

If I remember right, you can have two functions with the same name as long as their signatures are different. But yeah, I wouldn't do it either. Way too confusing.


And if you want to get a value from a function, why don't you just make the function that returns (gets) the value the same type as your value you want returned? Why try to do things the hard way if you don't have to?

This post has been edited by WabiSabi: 05 January 2012 - 03:59 PM

Was This Post Helpful? 0
  • +
  • -

#5 LordVicus  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 57
  • Joined: 05-November 09

Re: obtain a value from a void function

Posted 05 January 2012 - 04:05 PM

You can have void insert() in b.cpp require a reference parameter. When you call insert (b.cpp) from insert (a.cpp) pass a variable for insert (b.cpp) to store information in.

a.cpp

void insert(void)
{
type variable;
. . .
. . .
insert(variable);
}

b.cpp

void insert(type &var)
{
var = InsertTime;
. . .
. . .
}

This post has been edited by LordVicus: 05 January 2012 - 04:05 PM

Was This Post Helpful? 0
  • +
  • -

#6 Whizzy  Icon User is offline

  • D.I.C Head

Reputation: 26
  • View blog
  • Posts: 140
  • Joined: 29-November 10

Re: obtain a value from a void function

Posted 05 January 2012 - 06:12 PM

View Postwitchbanger, on 05 January 2012 - 10:10 PM, said:

That would be my guess. On a side note, while you are learning C++, take a course in grammar.

A little Harsh...

View PostLordVicus, on 05 January 2012 - 11:05 PM, said:

(type &var)
&var... You called it a reference parameter... isn't that a pointer, or are they different?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1