|
-
February 21st, 2006, 11:23 AM
#1
Converting Header from VC++ to MinGW
Hi,
I'm trying to use a dll which is supposed to work with practically any C++ compiler ( according to the author. ) The header files supplied seem to be set up for MS VC++ though. There are a number of errors, so I'll begin with the first one.
There's a struct definition that's causing an error to start with. I've trimmed it right down to make it easier to see the problem.
Code:
typedef struct MY_VECTOR
{
float x;
float y;
float MY_VECTOR::Dot(CONST MY_VECTOR& v)
{
return x*v.x + y*v.y;
}
} MY_VECTOR;
The error I get is that the compiler is expecting a ; after Dot and before ( in the declaration.
I'm really not sure what the problem is here. It looks fine to me, with my very limited C++ skills.
-
February 21st, 2006, 11:47 AM
#2
Re: Converting Header from VC++ to MinGW
For starters, this is pretty awful C++. It looks to me like a C programmer has read a couple pages of a C++ book and decided to have a go.
I can't remember if it's actually an error, but the "MY_VECTOR::" in front of Dot() is unnecessary (and may be illegal).
As for the rest of it; based on that example, I would probably avoid using it, since the author does not appear to know how to code C++ correctly. Using typedef is utterly pointless, and is an indicator of a C programmer. Leaving the data mambers public is dangerous, and would fail any serious code review. CONST is not a C++ keyword, and, if it's a macro, then it shows more wooly thinking.
The C++ way would look more like:
Code:
class MyVector
{
public:
float Dot(const MyVector& other) const
{
return x*other.x + y*other.y;
}
float X() const { return x; }
float Y() const { return y; }
private:
float x, y;
};
And I would throw in a couple of constructors for good measure.
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
-
February 21st, 2006, 02:26 PM
#3
Re: Converting Header from VC++ to MinGW
Hi Graham,
Thanks very much for the very quick and helpful response. The compiler seems happy to permit MY_VECTOR:: in front of Dot() so it must indeed have been the CONST which was making it error. I've gone through the headers and there seem to be a lot of similar keywords in caps, such as CONST and FLOAT. Perhaps these have some relevance if you're using VC++? I'm changing them all to lower case, and that seems to be letting it compile so far.
Thanks also for the suggestions on improving the code, I will go back and do that once I have everything at a point where it compiles.
The struct does have constructors, I just left them out to make the problem easier to diagnose, since there was no error with them.
Thanks again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|