global funtions

Started by
6 comments, last by karwosts 13 years, 6 months ago
i have made some funtions and would like to access them from any of my cpp files and classes in my program ,

but i am not sure how to do this.

declare them in a global.h and define them in a global.cpp , i tryed this but i got
an error

error LNK2019: unresolved external symbol "void __cdecl GetfacingVector(class tle::IModel *,struct D3DXVECTOR3 &)

in the cpp file its defined as
void GetfacingVector( IModel *model, D3DXVECTOR3 &dir)
{
// content
}

in classes you would say myclass::GetfacingVector( IModel *model, D3DXVECTOR3 &dir)

but i want to just be able to access it via code GetfacingVector

can you tell me what i am doing wrong plaease
Advertisement
Had an idea , but think it would have been wrong so its been edited out of existence..
Make sure you're spelling the function right the second time. Also make sure you're not defining something in a class then not putting the class marker on it. Example, defining a function as

void MyClass::MyFunction();

Then actually programming it as just void MyFunction();
Whats the code you used to declare it in global.h?
global.h


void GetParallelVector( IModel *model, D3DXVECTOR3 &dir);
void GetfacingVector( IModel *model, D3DXVECTOR3 &dir);
void GetPosVect(IModel *pModel,D3DXVECTOR3 &dir);



global.cpp


#include "global.h"



void GetfacingVector( IModel *model, D3DXVECTOR3 &dir)
{
float matrix[16];

model->GetMatrix( matrix );
dir.x = matrix[8];
dir.y = matrix[9];
dir.z = matrix[10];
}

void GetParallelVector( IModel *model, D3DXVECTOR3 &dir)
{
float matrix[16];

model->GetMatrix( matrix );
dir.x = matrix[0];
dir.y = matrix[1];
dir.z = matrix[2];
}



void GetPosVect(IModel *pModel,D3DXVECTOR3 &dir)
{
dir.x = pModel->GetX();
dir.y = pModel->GetY();
dir.z = pModel->GetZ();
}
You should read this.
Ensure you only have 1 global.cpp in the directories. The rule to make the file might select the wrong file if there are multiple copies in your folders.

a nice little check is place

#pragma message("can you read me")

If you see the message in you build log then you know its using the correct file.

Do the global.h and global.cpp files have proper knowledge of the IModel class? I assume that's not the entire header file. Are they both namespaced properly as tle::IModel?

Why don't you post your entire global .h/.cpp inside source tag so we can look at it, assuming you haven't fixed the problem.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game

This topic is closed to new replies.

Advertisement