d2jsp
Gaming and Trading Community
Gaming and Trading Community
Hourly Raffle
Ladder Slasher
Trade Finder
Photo Gallery
Forum Gold FAQ
Instant Messenger
Help and Rules
Live Streams
Account RecoveryResend Validation Email
Hello, GuestLog InRegister
d2jsp Forums > Programmer's Haven > C/C++/C# > Iso C++ Help

Add ReplyNew TopicNew Poll
Page 1 of 2 12
MsRailgun
#1 Jul 3 2012 07:25pm
Group: Members
Posts: 4,688
Joined: Feb 21 2011
Gold: 75.00
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.
AbDuCt
#2 Jul 3 2012 07:27pm
Group: Members
Posts: 8,550
Joined: Sep 29 2007
Gold: 719.06
Warn: 40%
Post your problems
MsRailgun
#3 Jul 3 2012 07:52pm
Group: Members
Posts: 4,688
Joined: Feb 21 2011
Gold: 75.00
Quote (AbDuCt @ Jul 3 2012 08:27pm)
Post your problems


Iso expertise.
AimfortheHead
#4 Jul 3 2012 10:33pm
Group: Members
Posts: 31,147
Joined: Jun 17 2006
Gold: 50,800.00
Warn: 10%
Mens is excellent with programming, PM him,

http://forums.d2jsp.org/user.php?i=797743
AbDuCt
#5 Jul 4 2012 12:26am
Group: Members
Posts: 8,550
Joined: Sep 29 2007
Gold: 719.06
Warn: 40%
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
MsRailgun
#6 Jul 4 2012 06:16am
Group: Members
Posts: 4,688
Joined: Feb 21 2011
Gold: 75.00
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 ._.
MsRailgun
#7 Jul 4 2012 06:52am
Group: Members
Posts: 4,688
Joined: Feb 21 2011
Gold: 75.00
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
KrzaQ2
#8 Jul 4 2012 07:35am
Group: Members
Posts: 9,441
Joined: Jun 28 2005
Gold: 250.33
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.
MsRailgun
#9 Jul 4 2012 08:44am
Group: Members
Posts: 4,688
Joined: Feb 21 2011
Gold: 75.00
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
KrzaQ2
#10 Jul 4 2012 09:23am
Group: Members
Posts: 9,441
Joined: Jun 28 2005
Gold: 250.33
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 C/C++/C# Topic List
Page 1 of 2 12