I want the constructor to create a dynamic array and assign arguments passed to the constructor to the members of the array.
A simplified version of what I have in the header:
//in classes.h
#ifndef classes_h
#define classes_h
#include <iostream>
class Base{
int a,*var;
public:
Base();
Base(int);
~Base();
int func(int);
};
#endif
And in the *.cpp:
//In classes.cpp
#incldue "classes.h"
Base::Base(int a){
var=new int[2];
var[0]=a;
var[1]=func(a);
}
Base::~Base(){
delete var;
}
int Base::func(int b){
return b++;
}
int main(){
Base obj(1);
return 0;}
I need to be able to pass that array to a function which will modify it in some way, but I'm actually having more trouble defining the array...
I don't get any errors from the compiler or linker, but by debugging I arrived at the conclusion the problem is around the creation of the array.
I went over the basics of pointers, dynamic arrays and classes 3 (or maybe more) times, but to no avail. I'm hoping what I'm trying to do is actually possible. If not, what's the closest thing?