Jump to content
  • Advertisement
Sign in to follow this  
ryt

How to use struct as a parameter in a module?

This topic is 3772 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

In VC++ I have built module.h and module.cpp. In module.h I have created struct vector3{}, and in module.cpp I have created a function in witch i want a paremeter to be vector3. Like function(vector3 *pVector);. But this cant be done cos it cant compile. How can I built a function in module.cpp that accepts vector3 as a parameter?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by ryt
In VC++ I have built module.h and module.cpp. In module.h I have created struct vector3{}, and in module.cpp I have created a function in witch i want a paremeter to be vector3.
Like function(vector3 *pVector);. But this cant be done cos it cant compile. How can I built a function in module.cpp that accepts vector3 as a parameter?
The way you have it there is correct, there must be some other problem. What's the exact error message?

Share this post


Link to post
Share on other sites
It compiles, and it works.

If your code doesn't work, you're probably doing it wrong. Since we cannot be expected to guess why, you should provide us with the exact error message, the line of code where it happens, as well as the definitions of all involved objects.

// module.h
struct vector3 {};

// module.cpp
void function(vector3 *vect) {}

Share this post


Link to post
Share on other sites
This is the header:

struct vector3
{
vector3(){}
vector3(float x, float y, float z)
{
_x = x; _y = y; _z = z;
}
vector3(float x, float y, float z, D3DXCOLOR color)
{
_x = x; _y = y; _z = z; _color = color;
}
float _x, _y, _z;
D3DXCOLOR _color;
static const DWORD FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
};

void pointPlane(int numberOfVerticesPerRow, int cellSpacing, float startX, float startZ, float endX, float endZ, vector3 *pPoints);
void pointPlaneIndices(int numberOfVerticesPerRow, int numberOfCellsPerRow, int numberOfCellsPerColumn, short *pIndices);



This is from .cpp:

void pointPlane(int numberOfVerticesPerRow, int cellSpacing,
float startX, float startZ, float endX,
float endZ, vector3 *pPoints) //<-- here is the error
{


This is the output from VC++:

Compiling...
pointPlane.cpp
c:\users\administrator\documents\visual studio 2008\projects\pointplaned3d9\pointplaned3d9\pointplane.cpp(17) : error C2061: syntax error : identifier 'vector3'
c:\users\administrator\documents\visual studio 2008\projects\pointplaned3d9\pointplaned3d9\pointplane.cpp(25) : error C2065: 'pPoints' : undeclared identifier
c:\users\administrator\documents\visual studio 2008\projects\pointplaned3d9\pointplaned3d9\pointplane.cpp(25) : error C3861: 'vector3': identifier not found

Share this post


Link to post
Share on other sites
Nope, I never did before also but it always worked (but i didnt use custom structs). Now that i include it i have eaven more errors, i need to chech them out.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!