views:

580

answers:

2

Hello. 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.

A: 

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.

GMan
Or Eigen or Armadillo for some template-ish solutions.
Dirk Eddelbuettel
Main is in a folder parallel to the one containing the headers and source files. And I'd like to edit the code I'm working with however I'm using it on a first time through educational purpose (my first time studying the material) so I need this supplied code to execute for now.
viperld002
+3  A: 

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.

Johannes Schaub - litb
That absolutely did it. Thank you very much for your advice. I didn't post the full code because I knew that was correct (obtained from an educational source), and the problem must have been something simpler that I was doing incorrectly. Once again thank you for your solution.
viperld002