Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: use shapes in vector  (Read 4889 times)

0 Members and 1 Guest are viewing this topic.

Jimicro

  • Newbie
  • *
  • Posts: 31
    • View Profile
use shapes in vector
« on: January 04, 2011, 10:05:46 pm »
I have a problem.

I have a class method where I declare a new Shape. i want to stack this in a vector.

Code: [Select]
#include <SFML/Graphics.hpp>
#include <iostream>
#include <vector>

class Circle : sf::Shape
{
    private:
    sf::Shape circle;
    int radius;
    std::vector <Circle*> circles;
    int x;
    int y;
    public:
    void generateCircle();
    void setValues(int x, int y);
    void draw(sf::RenderWindow& App);
    Circle();
};



and the method

Code: [Select]


void Circle::generateCircle()
{
    Circle* circle = new Circle;
    circles->sf::Shape ?
    circles.push_back(circle);
}

how can I declare the shape in to the vector?

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
use shapes in vector
« Reply #1 on: January 04, 2011, 10:49:22 pm »
circles.push_back(new Circle());

The new Circle object already contains a sf::Shape as a private member, even though it doesn't have an actual Circle associated with it.

I don't know your goal with that, but you should rethink your design, a lot of weird things there :P

Jimicro

  • Newbie
  • *
  • Posts: 31
    • View Profile
use shapes in vector
« Reply #2 on: January 04, 2011, 11:14:29 pm »
Quote from: "DevilWithin"
circles.push_back(new Circle());

The new Circle object already contains a sf::Shape as a private member, even though it doesn't have an actual Circle associated with it.

I don't know your goal with that, but you should rethink your design, a lot of weird things there :P


I have

Code: [Select]

void Circle::generateCircle()
{
    Circle* circle = new Circle;
    circle->sf::Shape::Circle(100, 50, 50, sf::Color::Red);
    circles.push_back(circle);
}



but it doesn´t save the attributes to the vector, I dont even know if it is possible to save them in vectors.

I need more than one circle and I thought the best way to stack them where in a vector.

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
use shapes in vector
« Reply #3 on: January 04, 2011, 11:24:56 pm »
Change from

Code: [Select]
circle->sf::Shape::Circle(100, 50, 50, sf::Color::Red);

to

 
Code: [Select]
circle->circle = sf::Shape::Circle(100, 50, 50, sf::Color::Red);

You will need to make the member sf::Shape circle a PUBLIC member for this code.

I still don't agree with your class design  :) But thats just me, lets see someone else's angle of it : )

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
use shapes in vector
« Reply #4 on: January 04, 2011, 11:57:29 pm »
Quote from: "DevilWithin"
I still don't agree with your class design  :) But thats just me, lets see someone else's angle of it : )
I haven't the time to explain, but I let you know you're not alone.  :wink:

Quickly :
a class «Circle» is not a «Collection of Circles». One may want a circle not in the collection but may not be able to – or will get confused.
SFML / OS X developer

 

anything