So, really weird thing is happening to me.
I´ve made a class Particle :
#pragma once
#include "ofMain.h"
class Particle {
Particle();
};
I declared it in my ofApp.h :
#pragma once
#include "ofMain.h"
#include "ofxSvg.h"
#include "Particle.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
Particle p;
//Particle ps [];
//vector <Particle> particles;
};
If I declared a single object I get this error of I declared an array of fixed elements I get this error:
'ofApp::ofApp(void)': attempting to reference a deleted function
But if I declared a vector of elements it works.What´s going on? What im missing?
arturo
April 13, 2018, 4:49pm
#2
you are making the constructor private, try:
#pragma once
#include "ofMain.h"
class Particle {
public:
Particle();
};
1 Like
oh sorry, I forgot to put public in this example but I was doing it right on mine.
My real problem is :
if you define a class constructor with a paramater, lets say :
#pragma once
#include "ofMain.h"
class Particle {
Particle(float _size);
};
In ofApp.h i put
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
Particle p;
//Particle ps [];
//vector <Particle> particles;
};
I get the error that I was saying, but only if I put a parameter inside de constructor function.
What should I do if
i´ve tryed :
Particle p(20);
inside ofApp.h but still getting this error. Thought I can use Particle if I make it a local variable inside a function, but can´t declare it in ofApp.h.
SOLVE IT ! .
So obvius
make 2 constructor functions inside my class. :
#pragma once
#include "ofMain.h"
class Particle {
public:
Particle();
Particle(float _size);
};
in ofApp.h now I can declare it normally :
Particle p;
And then in ofApp.cpp setup function inicialize like this :
p = Particle(20);
arturo
April 14, 2018, 10:23am
#5
yes when you declare a constructor with parameters the default constructor is not created anymore and you need to create it explicitly.
also if you really don’t want to have a default constructor you can also do in the declaration in ofApp.h
Particle p{20};
and even:
vector<Particle> ps{Particle{1}, Particle{2}, Particle{3}};
1 Like