Question

I've scoured the internet and my own intellect to answer this basic question, however, much to my own dismay I've been unable to find a solution. I'm normally pretty good about multiple header files however I have hit a wall. The problem is a function that I've declared in a header and defined in its proper namespace in the source file. I'm developing on windows using Bloodshed.

/////////////////////////////// // class Matrix4x3.h ///////////////////////////////

#ifndef _MATRIX4X3_H
#define _MATRIX4X3_H

class Matrix4x3{
    public:

        //set to identity
        void identity();

};

#endif

/////////////////////////////// // class Matrix4x3.cpp ///////////////////////////////

#include <assert.h>
#include <math.h>
#include "Matrix4x3.h"
.
.
.
void Matrix4x3::identity(){
    //calculations here...
}

////////////// Main ////////////////

#include <cstdlib>
#include <iostream>

#include "../Matrix4x3.h"

using namespace std;

int main(int argc, char *argv[])
{
    Matrix4x3 a;

    a.identity();

    cin.get();
    return EXIT_SUCCESS;
}

I use Bloodshed, and it displays a list of class members and methods when I use the constructed object, however it tells me that the method dipicted above hasn't been referenced come time to compile. If anyone has a response I would be very appreciative.

Was it helpful?

Solution

If you compile using the IDE, look for some button like "add file to project" or something like this, to add the Matrix4x3.cpp file to your project, so that when you build it, the IDE will put the translated result to the linker and all functions are resolved.

Currently, it looks like you don't tell the IDE about that cpp file, and so that function definition is never considered.

OTHER TIPS

I think litb has it right.


On a totally unrelated note, you might want to look into templates so you can have this class:

template <size_t Rows, size_t Columns>
class Matrix
{
    ...
};

typedef Matrix<4, 3> Matrix4x3;

Instead of a new class for each matrix size. You might also throw the type into the mix:

template <size_t Rows, size_t Columns, typename T>
class Matrix
{
    ...
};

typedef Matrix<4, 3, float> Matrix4x3f;
typedef Matrix<4, 3, double> Matrix4x3d;

Or look into boost.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top