Learning the classes and object based programming

Hello

Unfortunately I must learn the classes in the complex environment, any help is highly appreciated.

I have the function in class which checks if two cuboids are intersecting or not:

 
Poly::intersecting(const Cuboids& cuboids, const Quaternion<float>& rotation, const int32_t index) const


This function returns true or false regarding the new cuboids intersects with other cuboid. I need to write new function which uses that function, and if it is false(meaning that cuboids does not intersect each other) they must be connected with each other:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void
Poly::add(const Cuboid &cuboid, const Quaternion<float> &rotation)
{

    for (Cuboid i = 0; i < number_of_cuboids(); i++)
    {
        auto intersection =intersecting(_cuboid[i],_rotations[i], i);

        if (intersection = false) {

            _cuboids = _cuboids.push_back(i);

            _rotations = _rotations.push_back(i);
        }
    }


However I have a strong feeling that I am simplifying everything too much, and it is wrong. In general, it should check if current cuboid intersecting with any of previous, and if not, then should be added to the vector of cuboids (poly)

Thanks!
Last edited on
Well, we can't really see all that much, but....


It doesn't seem you're using the parameters for anything.

Also, intersection = false is an assignment, not a test - the compiler should issue a warning.

Is the type Cuboid an integer? It is being used as an index to apparently the member array _cuboid. Then, too, I can't see what container _cuboid is, so I might be totally lost trying to read this.



get the logic and math and all down. Forget the object part, mostly: inside your class method, which is just a normal function with some extra qualifiers on it, the class variables are effectively globals, and in there you can just code it. Get that down and if any of the class stuff gives trouble, show us and ask, but from what we have seen the class stuff here is going to be the least of your worries.

== means 'is this equal to that'
= mean 'make this equal to that'
and the language will let you use = where you meant == (with a warning as noted above) but its a common mistake that you need to always watch for.
Thank you. I got it wrong , then, the problem is not a class, but the function, cannot understand it. Class description

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Poly::Poly()

    : _cuboids(std::vector<Cuboid>())
	
	, _label_p(std::string())
	
	, _origin_x(0.0f)

        , _origin_y(0.0f)

        , _origin_z(0.0f)
	
	, _rotations(std::vector<Quaternion<float>>())


Function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void
Poly::add(const Cuboid &cuboid, const Quaternion<float> &rotation)
{

    for (Cuboid i = 0; i < number_of_cuboids(); i++)
    {
        auto intersection =intersecting(_cuboid[i],_rotations[i], i);

        if (intersection == false) {

            _cuboids = _cuboids.push_back(i);

            _rotations = _rotations.push_back(i);
        }
    }



I fixed the == , and when trying to use
 
_cuboids = _cuboids.push_back(i);


getting the IDE error: no matching member function for call to 'pushback'
Hmmm...that's not a class description. That's a class constructor function. I can't, for example, see the type of _cuboids still. I can see it consumes a temporary vector that takes a Cuboid, but I still don't know what a Cuboid is, really.

Further, even if _cuboids was a vector, it doesn't return a vector for assignment to _cuboids. A push_back is typically used:

_cuboids.push_back( c );

We don't typically take an assignment from that.

Sorry, the description is shown below. I am really sorry for such unclear question; however, so it happened that I must learn basics right from the middle of quite complex code.

1
2
3
4
5
6
7
8
class Poly
{
    std::vector<Cuboid> _cuboids;
    std::string _label_p;
    float _origin_x;
    float _origin_y;
    float _origin_z;
    std::vector<Quaternion<float>> _rotations;


in general, I need to take the i element of vector cuboid, check it against the function intersecting, if I get false, I must it add to the vector. So currently the function is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
void
Poly::add(const Cuboid &cuboid, const Quaternion<float> &rotation)
{
    for (int32_t i = 0; i < number_of_cuboids(); i++)
    {
        auto intersection =intersecting(_cuboids[i],_rotations[i], i);

        if (intersection == false) {

            _cuboids.push_back(i);

            _rotations.push_back(i);
        }
    }


I still see the warning that _cuboids.push_back(i) : no matching member function for call to 'pushback'

Last edited on
Topic archived. No new replies allowed.