d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Iso C++ Help
12Next
Add Reply New Topic New Poll
Member
Posts: 19,514
Joined: Feb 21 2011
Gold: 3,877.57
Jul 3 2012 07:25pm
I need someone highly knowledgeable in C++. Of course, I will be paying for the work and solution. The time limit is about a day or two. I'll be pming you the problem and specifications.
Please post or pm me if you are interested. It will be worth your time:fg.
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Jul 3 2012 07:27pm
Post your problems
Member
Posts: 19,514
Joined: Feb 21 2011
Gold: 3,877.57
Jul 3 2012 07:52pm
Quote (AbDuCt @ Jul 3 2012 08:27pm)
Post your problems


Iso expertise.
Member
Posts: 43,599
Joined: Jun 17 2006
Gold: 1,330.00
Jul 3 2012 10:33pm
Mens is excellent with programming, PM him,

http://forums.d2jsp.org/user.php?i=797743
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Jul 4 2012 12:26am
Quote (MsRailgun @ Jul 3 2012 09:52pm)
Iso expertise.


uh? i guess that means list all the ways i am better than you...

i know c, c++, vb6, vb.net c#.net, pascal, delphi, asm 32bit at&t system v syntax, as well as some knowledge in php, ruby, perl, and python. i have knowledge varying subjects such as encryption, sockets, and understand basic and advanced logic control schemes.

dont feel like helping now because you made me type instead of just typing your fucking problem. prolly has to do with some bot anyways.

This post was edited by AbDuCt on Jul 4 2012 12:28am
Member
Posts: 19,514
Joined: Feb 21 2011
Gold: 3,877.57
Jul 4 2012 06:16am
Quote (AbDuCt @ Jul 4 2012 01:26am)
uh? i guess that means list all the ways i am better than you...

i know c, c++, vb6, vb.net c#.net, pascal, delphi, asm 32bit at&t system v syntax, as well as some knowledge in php, ruby, perl, and python. i have knowledge varying subjects such as encryption, sockets, and understand basic and advanced logic control schemes.

dont feel like helping now because you made me type instead of just typing your fucking problem. prolly has to do with some bot anyways.


It goes without saying, anyone who views this thread would be better than me, or why else would they be here?
I guess I'll just post my questions instead ._.
Member
Posts: 19,514
Joined: Feb 21 2011
Gold: 3,877.57
Jul 4 2012 06:52am
Here's the question;
The following classes and main are from
http://cboard.cprogramming.com/cplusplus-programming/100352-array-base-abstract-class-problem.html

#include <iostream>

class Base{

public:

virtual void doSomething(){
std::cout << " - - - - " << std::endl;
}

};

// - - - - - - - - - - - - - - - - - - - - - - - -

class Extended : public Base{

public:

void doSomething(){
std::cout << "Doing something..." << std::endl;
}

};

// - - - - - - - - - - - - - - - - - - - - - - - -


// ------ NEW
void helper_func(Base* objs[]) {
objs[0]->doSomething();
}
//-----

int main(int argc, char* argv[]){

Base baseObj;
Extended *extensionObj = new Extended;

Base *objs[2];
objs[0] = &baseObj;
objs[1] = extensionObj;

objs[0]->doSomething();
objs[1]->doSomething();

///--- new
helper_func(objs);
//----
return 0;
}


Now the question is, if we take at the routine helper_func and the call to it in main, how would I be able to replace:

void helper_func(Base* objs[])
to
void helper_func(Base& ...) where .. is whatever, but Base& must be there - since I want to use a reference. (This is a specification).

In reflection of this change, what would be the change to the call?: helper_func(objs);

I still want it to do exactly the same thing as above, where the array of pointers to a base can be accessed "normally" in another function.

Question 2: I want to clarify if the following will delete the memory reserved.
delete objs[0];
delete objs[2];

Thank you~
100 fg to the first correct solution.

This post was edited by MsRailgun on Jul 4 2012 06:57am
Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
Jul 4 2012 07:35am
You can use code tags ;)

helper func - depends on what you want the reference to refrence ;)

if it's a single object, just do

Code
void helper_func(Base& obj)
{
obj.doSomething();
}

and call it like this:
helper_func(*objs[0]);

if you want to reference the array instead
Code
void helper_func(Base* (& objs)[2]) {
objs[0]->doSomething();
}

And you don't change your calling code either, but I don't think that's what you wanted.

Q2:
You don't need to delete [0], because it has automatic storage class and [2] is out of bounds of your array. You should delete [1] though.
Member
Posts: 19,514
Joined: Feb 21 2011
Gold: 3,877.57
Jul 4 2012 08:44am
Quote (KrzaQ2 @ Jul 4 2012 08:35am)
You can use code tags ;)

helper func - depends on what you want the reference to refrence ;)

if it's a single object, just do

Code
void helper_func(Base& obj)
{
obj.doSomething();
}

and call it like this:
helper_func(*objs[0]);

if you want to reference the array instead
Code
void helper_func(Base* (& objs)[2]) {
objs[0]->doSomething();
}

And you don't change your calling code either, but I don't think that's what you wanted.

Q2:
You don't need to delete [0], because it has automatic storage class and [2] is out of bounds of your array. You should delete [1] though.


Q2:
Ah yes, my mistake on deleting 2, meant 1 :)

For Q1, it still isn't what I need.
Code
void helper_func(Base* (& objs)[2]) {
objs[0]->doSomething();
}


I need the parameter to be (Base& ...) where .. can be replaced with a parameter name. So i want to pass by reference.

The other solution;

Code
void helper_func(Base& obj)
{
obj.doSomething();
}

Is kind of what I want but I want it for the whole array. Thus I want to access obj[2] as well, etc.

The point is so I can access the whole array in the other function and change it as well. And not make a copy of it.

This post was edited by MsRailgun on Jul 4 2012 08:45am
Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
Jul 4 2012 09:23am
You already are not making copying the array. You can't pass an array of references, but you can simplify your syntax a little and use

Code
void helper_func(Base* objs) {
objs[0]doSomething();
}


With calling code being

helper_func(objs[0])

or

helper_func(*objs)

If you really want a reference, try using a container cass like vector.
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll