OOP doubth extending class constructor problem

Hi

I have a class “baseShape” that extends ofRectangle, this is going to be my main class. From this class i derived other class named “boton” so i ended with a class called button witch extends “baseShape”.

When i try in the class “boton” to get a var or a method from his parent class “baseShape” i allways get an error

main class “baseShape”

  
  
class baseShape : public ofRectangle {  
public:  
	baseShape();  
	~baseShape();  
........  
  

boton class extends baseShape

  
  
class boton : public baseShape {  
public:  
    boton();  
    ~boton();  
....  
  

it seems like in this class (“boton”) the constructor of the parent class was not called so i dont have access to the parent class properties or methods.

What im doing wrong?

thanks for reading!

that seems doubtful - when constructing a derived class object, the base class constructor is called first automatically. see http://www.learncpp.com/cpp-tutorial/114-constructors-and-initialization-of-derived-classes/

could you post code demonstrating the problem?

[]](http://[url)Thanks-for-your-answer,-so-after-reading-that-doc-seems-like-the-problem-has-to-come-from-another-place.-Maybe-the-way-I’m-using-the-classes.–

i-attached-an-Xcode-project,-the-class-called-“fichaInfo”-is-where-i-used-the-classes-“boton”-and-“visualizador”-that-extends-the-baseShape-class-wich-extends-ofRectange…–

Maybe-the-problem-is-that-im-using-the-classes-in-this-way:–

--
class-fichaInfo-{--
public:--
	fichaInfo();--
	~fichaInfo();--
......--
----//-piezas-para-la-figura--
	vector<baseShape*>-rectangulos;-///-el-vector-es-para-la-colision-entre-ellos--
	vector<Spring*>-muelles;--
--
--------boton-*-btnImagenes;--
	boton-*-btnCuadros;--
	boton-*-btnPeriodicos;--
	visualizador-*-areaGrande;--
--
--


when-i-declare-a-pointer-in-the-header-file…-the-constructor-of-that-pointer-is-automatically-called-no?–

dropbox-link-(it-takes-a-few-minutes-to-be-ready)–
https://dl.dropbox.com/u/64603807/tactil.zip

thanks for your time

not directly related to the problem you state, but read these:
http://pages.cs.wisc.edu/~cs368-2/CppTutorial/NOTES/CLASSES-PTRS.html
http://stackoverflow.com/questions/9000636/should-we-explicitly-write-a-copy-constructor-if-the-class-member-is-a-vector
http://stackoverflow.com/questions/3740471/c-copy-constructor-pointer-object

btw, an XCode project is not useful to all users, so it’s often more useful to just post the code of a minimal/reduced example which shows your problem.

Thanks!!

im sorry about the project, your are right its better to explain what im doing wrong… so this can be usefull for anothers.

Im doing is a class “fichaInfo” that its made by various rectangles connected with springs, in the header file of that class i have the following pointers:

i declare here the pointers because i want to call them independientemente

  
  
boton * btnImagenes;  
boton * btnCuadros;  
boton * btnPeriodicos;  
visualizador * areaGrande;  
  

and a vector to store all the pointers, i use a vector because i need to loop them to set a repulsion force between the shapes

  
  
vector<baseShape*> rectangulos;  
  

I assumed that when you declare a pointer in the header file, the object is automatically created, but im wrong. So later i have to initialize the pointer to use in a function.

wrong

  
  
void fichaInfo::construFigura(){  
btnImagenes->x;  
}  
  

works

  
  
void fichaInfo::construFigura(){  
boton * btnImagenes = new boton();  
btnImagenes->x;  
}  
  

later in this function i pushed the pointer to the vector

  
  
rectangulos.push_back(btnImagenes);  
  

The funny thing its that i can access to the pointers through the vector, anywhere. So in another function of this class i can make

  
  
for(int i = 0; i < rectangulos.size(); i++){  
		rectangulos.at(i)->drawRound();  
}  
  

but i can NOT call a pointer directly

  
  
btnImagenes->drawRound();  
  

hi panderoto,

i don’t see your code in the dropbox any longer, but what i think what you want to be doing is this:

  
  
rectangulos.push_back( new boton() );  
  

Thanks for your answer…

But, what is the difference between:

  
  
boton * btnImagenes = new boton();    
rectangulos.push_back(btnImagenes);    
  

and

  
  
rectangulos.push_back( new boton() );  
  

sorry, i didn’t finish that reply. you are right, those would both work the same. what i meant to point out was that if you declare a pointer in the header and allocate it, it should only be pushed once to the vector, but re-reading it looks like you are not doing that at all. you should, however, be able to access the methods from your pointer, but its hard to tell why that is not working…

Yes, thanks for your answer.

I can access to the methods thought the vector, but not from the declared pointers in the header… seems like its not a good way of doit so i take another aproach

Yet im still curious about why is not working