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 2 of 2 12
irimi
#11 Jul 4 2012 09:56am
Group: Members
Posts: 3,594
Joined: Sep 15 2011
Gold: 1,771.00
Quote (MsRailgun @ Jul 3 2012 06:52pm)
Iso expertise.


i lol'd
MsRailgun
#12 Jul 4 2012 12:45pm
Group: Members
Posts: 4,647
Joined: Feb 21 2011
Gold: 75.00
Code

#include <iostream>
#include <vector>

using namespace std;

int ii = 90;
class Base{
protected:
 int i;
public:
 Base(int i) { cout << "INITIALIZED" << endl; }
 virtual void setnum(int u) = 0;
 virtual void doSomething(){
   cout << " - - - - " << endl;
 }

};

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

class Extended : public Base{
public:
 Extended(int z) {
   i = z;
 }
 void setnum(int u) {
   i = u;
 }
 void doSomething(){
   cout << "Doing something..." << i << endl;
 }

};
typedef vector<Base*> BVector;

void helper_func(BVector& objs) {
 BVector temp;
 temp = objs;
 temp[1]->setnum(1338);
}


int main(int arg, char* argv[]) {
 Extended *extensionObj = new Extended(1337);
 vector<Base*> head(2);
 head[1] = NULL;
 head[2]= NULL;
 vector<Base*> objs;
 head[0] = new Extended(999);
 head[1] = extensionObj;
 objs = head;
 objs[0]->doSomething();
 objs[1]->doSomething();

 helper_func(objs);
 objs[1]->doSomething();
 cout << ii << endl;
 ii = ii + 1;
 cout << ii << endl;

 delete objs[0];
 delete objs[1];
 return 0;


}


There's a compile error involving the constructors - I hope someone can shed some insight and a solution?
I understand there's 1 way to get it working by
public:
Extended(int z) : Base(z) {
i = z;
}

But I want another solution which will not use this notation.
irimi
#13 Jul 4 2012 09:43pm
Group: Members
Posts: 3,594
Joined: Sep 15 2011
Gold: 1,771.00
Quote (MsRailgun @ Jul 4 2012 11:45am)

But I want another solution which will not use this notation.

why?
MsRailgun
#14 Jul 5 2012 05:21am
Group: Members
Posts: 4,647
Joined: Feb 21 2011
Gold: 75.00
Ugh, forget my last question, there were some misinterpretations.
Otherwise, KrzaQ2 solved my original problem - once again, thanks to all who contributed.
Go Back To C/C++/C# Topic List
Page 2 of 2 12