How to use struct as a parameter in a module?

Started by
5 comments, last by fpsgamer 15 years, 9 months ago
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?
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?
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.hstruct vector3 {};// module.cppvoid function(vector3 *vect) {}
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
Did you #include the header in the .cpp file?
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.
Quote:Original post by ryt
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.


Organizing Code Files in C and C++

This topic is closed to new replies.

Advertisement