Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <iostream>
using namespace std;
class Whatever {
private:
float *color;
public:
Whatever();
Whatever(float*);
~Whatever();
float* getColor();
void printColor();
};
Whatever::Whatever() : color(new float[3]) {
color[0] = 0.0;
color[1] = 0.0;
color[2] = 0.0;
}
Whatever::Whatever(float* _c){
color[0] = _c[0];
color[1] = _c[1];
color[2] = _c[2];
}
Whatever::~Whatever(){
delete [] color;
}
float* Whatever::getColor(){
return color;
}
void Whatever::printColor(){
cout << "Color is: (" << color[0] << ", " << color[1] << ", " << color[2] << ")" << endl;
}
int main(int argc, char** argv){
{
Whatever w;
w.printColor();
}
//{
float* color = new float[3];
color[0] = 1.0;
color[1] = 1.0;
color[2] = 1.0;
Whatever w(color);
w.printColor();
delete[] color;
//}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.