Hi, I've been programming a lot of c code,
and now I'm trying to set my mind into the c++ way of doing things.
so I'm trying to avoid pointers, and use refs instead.
As far as I understand pointers are to be avoided using stl's for instance.
I have 2 matrix classes that I want to contain in another class.
But at runtime I only want one of the matrixobjects allocated and instantiated.
In good old c, I would have made a pointer to the object,
and then only allocated the one I wanted.
But It seems that you need to instantiate everything in a class.
Or am I trying to do this in a odd way?
I think the problem is in class "aCollector" at line 20-27
#include <iostream>
class aClass{
public:
float f1;
float f2;
int *array;
aClass(float var1, float var2){printf("norm class construct\n");f1=var1;f2=var2;}
};
template <typename T>
class aTemplate{
float f1;
float f2;
T *array;
aTemplate(float var1, float var2){printf("template class constructor\n");f1=var1;f2=var2;}
};
class aCollector {
public:
int a;
int b;
aCollector(int chooseType,int f, int g): (chooseType==0)?myTemplate(f,g):myobj(fg){}
aTemplate<int> myTemplate;
aClass myobj;
};
int myFun(aStruct as){
return 0;
}
int main(){
aCollector acol(2,3);
return 0;
}
thanks in advance