//
// main.cpp
// question
//
// Created by admini on 6/9/15.
// Copyright (c) 2015 admini. All rights reserved.
//
#include <iostream>
usingnamespace std;
class a {
int a_data;
public:
a()
{
a_data = 1;
}
void set_a_data(int input)
{
a_data = input;
}
};
class b : public a {
int b_data;
public:
void set_b_data(int input)
{
b_data = input;
}
};
class helperClass {
public:
a* add_bClass_data_return_aClass(int bInput )
{
b* bInstance;
bInstance->set_a_data(bInput);
return bInstance;
}
};
static helperClass *A_helperClass;
int main(int argc, constchar * argv[]) {
const a *a_aClass;
a_aClass = A_helperClass->add_bClass_data_return_aClass(5);
return 0;
}
please excuse the format of main. I cannot modify main for this assignment. Is it possible to do what I am thinking? OR do I need to just explicitly pass bClass as a bClass and let inheritance do its job? so to speak. Let me know if you need more info or if something does not make sense.
I think helperClass was something like a nested public static ? if so, forget about that, there are dirty things in java ; loved by java devs only ; nested static is one of the thing, and has no place in c++.
I don't understand what you try to achieve ; in c++ we don't use global static ;
in c++ you can deference pointers, if you wish to, if you are using a virtual you can cast a "b" to an "a" and call set on it, you'll see what happens.
I am not sure. I just need to make it work. The assignment has a main class with a global static class. Now it is my job to write the implementation and NOT edit the main file.
In other words... (minus the global static issue - as that might work out to be trivial as I get further into the assignment )
Say class shape
then we have a circle class that is derived from shape
then we have a box class that is derived from shape
then we have a diamond class that is derived from shape
Now my helper class has a function that is
then method is
shape addCircle( circle and shape params )
{
// create new circle
// return circle as a shape?
// or just return a circle?
}
so that I can call the method as
Shape aShape;
aShape = helperFunction->addCircle( circle and shape params ) ;
I'm not sure what you are asking. But I noticed this.
In helperClass, on line 48, bInstance is uninitialized. To solve this you may want to do: b* bInstance = new b;.
Remember to delete bInstance; after you have finished using it.