static functions

  • Thread starter michael.goossens
  • Start date
M

michael.goossens

Alright I am implementing a static member function for the first time
and it is not working :(. Are static member functions implemented in
the header?

header:

static float[4][8] GetPivot(float matrix[4][8], int n);

cpp:

static float[4][8] Matrix4x4::GetPivot(float matrix[4][8], int n) {
...
}

and the errors:

1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.h(12) : error C3409: empty attribute block is
not allowed
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.h(12) : error C2143: syntax error : missing ']'
before 'constant'
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.h(12) : error C2059: syntax error : 'constant'
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.h(12) : error C2238: unexpected token(s)
preceding ';'
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.cpp(61) : warning C4091: 'static ' : ignored on
left of 'float' when no variable is declared
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.cpp(61) : error C2143: syntax error : missing
';' before '['
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.cpp(61) : error C3409: empty attribute block is
not allowed
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.cpp(61) : error C2143: syntax error : missing
']' before 'constant'
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.cpp(61) : error C2059: syntax error :
'constant'
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.cpp(61) : error C2039: 'GetPivot' : is not a
member of 'Matrix4x4'
1> c:\users\michaël\documents\visual studio 2005\projects
\renderwoman\renderwoman\matrix4x4.h(4) : see declaration of
'Matrix4x4'
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.cpp(61) : error C2143: syntax error : missing
';' before '{'
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.cpp(61) : error C2447: '{' : missing function
header (old-style formal list?)
1>Transform.cpp
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.h(12) : error C3409: empty attribute block is
not allowed
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.h(12) : error C2143: syntax error : missing ']'
before 'constant'
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.h(12) : error C2059: syntax error : 'constant'
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.h(12) : error C2238: unexpected token(s)
preceding ';'
 
V

Victor Bazarov

Alright I am implementing a static member function for the first time
and it is not working :(. Are static member functions implemented in
the header?

Not sure what you mean by "are". Mine aren't _usually_. If they are,
they are declared 'inline' (or implicitly inline if defined inside the
class definition).
header:

static float[4][8] GetPivot(float matrix[4][8], int n);

You can't return an array.
cpp:

static float[4][8] Matrix4x4::GetPivot(float matrix[4][8], int n) {

Drop 'static' from here. And fix the return value type.
...
}

and the errors:

1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.h(12) : error C3409: empty attribute block is
not allowed
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.h(12) : error C2143: syntax error : missing ']'
before 'constant'
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.h(12) : error C2059: syntax error : 'constant'
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.h(12) : error C2238: unexpected token(s)
preceding ';'
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.cpp(61) : warning C4091: 'static ' : ignored on
left of 'float' when no variable is declared
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.cpp(61) : error C2143: syntax error : missing
';' before '['
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.cpp(61) : error C3409: empty attribute block is
not allowed
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.cpp(61) : error C2143: syntax error : missing
']' before 'constant'
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.cpp(61) : error C2059: syntax error :
'constant'
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.cpp(61) : error C2039: 'GetPivot' : is not a
member of 'Matrix4x4'
1> c:\users\michaël\documents\visual studio 2005\projects
\renderwoman\renderwoman\matrix4x4.h(4) : see declaration of
'Matrix4x4'
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.cpp(61) : error C2143: syntax error : missing
';' before '{'
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.cpp(61) : error C2447: '{' : missing function
header (old-style formal list?)
1>Transform.cpp
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.h(12) : error C3409: empty attribute block is
not allowed
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.h(12) : error C2143: syntax error : missing ']'
before 'constant'
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.h(12) : error C2059: syntax error : 'constant'
1>c:\users\michaël\documents\visual studio 2005\projects\renderwoman
\renderwoman\matrix4x4.h(12) : error C2238: unexpected token(s)
preceding ';'

V
 
M

michael.goossens

How do I fix that? Tried to return &matrix instead and catch that as a
float *, but that didn't work :(.
 
V

Victor Bazarov

How do I fix that? Tried to return &matrix instead and catch that as a
float *, but that didn't work :(.

You can wrap your array in a struct and return that struct.

V
 
C

C++ Enthusiast

You can wrap your array in a struct and return that struct.

V

Return matrix (not &matrix) and assign that to float*. matrix itself
is the address of the array. Hope that helps.
 
J

James Kanze

(e-mail address removed) wrote:
header:
static float[4][8] GetPivot(float matrix[4][8], int n);
You can't return an array.

But you can return a pointer to an array:

static float (*getPivot( float m[4][8], int n ))[8] ;

Note that the reinterpretation of array type as pointer type
doesn't apply to return values. In the above declaration, the
type of parameter m and the return type are identical.

Note to that if you write something like:

float (*getPivot( float m[4][8], int n))[8]
{
float result[4][8] ;
// ...
return result ;
}

you will end up returning a pointer to a local variable. Not a
good idea either.

Given this, and the awkward syntax required in the declarations,
I'd strongly suggest never using C style arrays in this context.
boost::array would do the trick here (and will be part of the
next standard); otherwise, at the very least, wrap the array in
a struct (but I suspect that in the actual application, a full
class might be even more appropriate).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top