Advertisement Jump to content
Sign in to follow this  

Silly c++ error

This topic is 3962 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I know what this message MEANS because I forgot to put the destructor in the class header: /Users/speciesunknown/Projects/newton_collision/current_copy/OSX/physics_object.cpp:36: error: definition of implicitly-declared 'physics_object::~physics_object()' /Users/speciesunknown/Projects/newton_collision/current_copy/OSX/physics_object.cpp:36: error: declaration of 'physics_object::~physics_object()' throws different exceptions /Users/speciesunknown/Projects/newton_collision/current_copy/OSX/physics_object.h:25: error: than previous declaration 'physics_object::~physics_object() throw ()' But, can somebody explain to me why it gives these errors, rather than something simple like "ZOMG you can't implicitly declare the destructor!". Does it mean there is something more complicated wrong with my class? Here is the class header:
class physics_object;

#ifndef class_physics_object_h
#define class_physics_object_h 1

//middleware and std c++
#include <vector>
#include "Newton.h"
#include "dMatrix.h"

//own stuff
#include "ac3d_model.h"
#include "g_maths.h"

class physics_object
        NewtonWorld * world;
        NewtonBody * body;
        NewtonCollision * collision;
        bool ready;
        g_vector position;
        float matrix[16];
        void load_test_geometry(dFloat X, dFloat Y, dFloat Z);
        physics_object(NewtonWorld * w);
        NewtonBody * get_body()const{return body;}
        NewtonCollision * get_collision()const{return collision;}
        void update();//read new position / orientation of physics_body and update yourself
        void debug();//report location.

and the implementation:
 *  physics_object.cpp
 *  game_engine
 *  Created by shotgunnutter on 09/03/2008.
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
#include <iostream>
#include "physics_object.h"
// add force and torque to rigid body
void PhysicsCubeApplyForceAndTorque (const NewtonBody* body)
    dVector force (0.0f, -9.8f, 0.0f);
    NewtonBodyAddForce (body, &force.m_x);

// set the transformation of a rigid body
void  PhysicsCubeSetTransform (const NewtonBody* body, const dFloat* matrix)
    //RenderPrimitive* primitive;

    // get the graphic object from the rigid body
    //primitive = (RenderPrimitive*) NewtonBodyGetUserData (body);

    // set the transformation matrix for this rigid body
    //dMatrix& mat = *((dMatrix*)matrix);
    //primitive->SetMatrix (mat);

physics_object::physics_object(NewtonWorld * w)
    world = w;
    NewtonReleaseCollision (world, collision);

void physics_object::load_test_geometry(dFloat X, dFloat Y, dFloat Z)
    collision = NewtonCreateBox (world, 1, 1, 1, NULL); 
    body = NewtonCreateBody (world, collision);
    NewtonBodySetMassMatrix (body, 1.0f, 1.0f, 1.0f, 1.0f);
    dMatrix location (GetIdentityMatrix());
    location[3][0] = X;
    location[3][1] = Y;
    location[3][2] = Z;

    // set the transformation for the box
    NewtonBodySetMatrix (body, &location[0][0]);    //create a block to hit the floor        
    // set the transform call back function
    NewtonBodySetTransformCallback (body, PhysicsCubeSetTransform);
    // set the force and torque call back function
    NewtonBodySetForceAndTorqueCallback (body, PhysicsCubeApplyForceAndTorque);    

    //clean up

void physics_object::update()
{//read new position / orientation of physics_body and update
    dMatrix position;
    NewtonBodyGetMatrix(body, &position[0][0]);
    int mindex = 0;
    for(int x=0; x<4; x++)
    for(int y=0; y<4; y++){
        matrix[mindex++] = position[x][y];

void physics_object::debug()
    dMatrix position;
    NewtonBodyGetMatrix(body, &position[0][0]);
    for(int x=0; x<4; x++)
    for(int y=0; y<4; y++){

Can anybody see any issues that might have caused the extra verbosity from the compiler? Thanks.

Share this post

Link to post
Share on other sites
Lets imagine you wrote an explicit destructor, like the compiler's version. It would appear the the compiler defaults to a non-throwing destructor (which is reasonable, destructors should never throw exceptions). You implemented a destructor with a different throw specification, and the compiler flags an error:

class Example
~Example() throw();

Example::~Example() // no throw specification
// ...

G++ says:

declaration of `Example::~Example()' throws different exceptions
than previous declaration `Example::~Example() throw ()'

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!