Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Zakalwe
May 12, 2002

Wanted For:
  • Terrorism
  • Kidnapping
  • Poor Taste
  • Unlawful Carnal Gopher Knowledge

brian posted:

I'm having trouble using a really old fixed point library in VC++ 2008, any time I use the following two ASM based functions I get linking errors and I have no idea to fix it, is it a compiler flag I have to enable? I really need the fixed multiplication and division to be as fast as possible, it's for music generation on the GP2X which doesn't have an FPU.

code:
fp14
fpDiv(fp14 d1, fp14 d2);
#pragma aux fpDiv = \
    "xor    edx, edx" \
    "shld   edx, eax, 14" \
    "sal    eax,14" \
    "idiv   ebx" \
    parm [eax] [ebx]\
    modify [edx] \
    value [eax];

fp14
fpMul(fp14 m1, fp14 m2);
#pragma aux fpMul = \
    "imul   ebx" \
    "shrd   eax, edx, 14" \
    parm [eax] [ebx]\
    modify [edx]\
    value [eax];
It's throwing unresolved externals even though I think i'm including everything correctly.


Wrong question. You're trying to compile x86 asm for an ARM CPU. Not going to happen.

Adbot
ADBOT LOVES YOU

brian
Sep 11, 2001
I obtained this title through beard tax.

Bugger, this is really annoying, I tried another fixed library but it was slower than using floats, although that is probably just due to the sine function it has being slower than if I used a sine table.

POKEMAN SAM
Jul 8, 2004

brian posted:

Bugger, this is really annoying, I tried another fixed library but it was slower than using floats, although that is probably just due to the sine function it has being slower than if I used a sine table.

Then why not just write your own sin function that uses a table?

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

Anyone know of a portable ANSI C XML generation (not parsing) library? I don't think writing some code to spit out XML as I walk through my data will be that hard, but I'd rather not reinvent the wheel if I don't have to. This is for an 8051 derivative microcontroller, so the perfect library would have a tiny memory footprint. Even if I can't find exactly what I want, I'm still interested in checking out how some other people handled this.

e: I figured out that -"C#" and -"C++" are my friends when doing a google search for ansi C stuff. I found genx. I'd still love to hear about any others, though.

taqueso fucked around with this message at 18:47 on May 8, 2009

OddObserver
Apr 3, 2009

Zakalwe posted:

Wrong question. You're trying to compile x86 asm for an ARM CPU. Not going to happen.

These 2 look portable to C, albeit I am not sure about the idiv --- it's a 64-bit over 32-bit division, isn't it?

Chuu
Sep 11, 2004

Grimey Drawer
I am doing something really stupid with fstream but cannot figure out what. I want to open a file, read all the contents, and start appending to it.

code:
std::fstream m_file;
m_file.open(filename.c_str(), std::ios_base_in | std::ios_base::out | 
     std::ios_base::ate | std::ios_base::app)
m_file.seekg(std::ios_base_beg);

if(!m_file.is_open()){
	...
}

while(!m_file.eof())
{
	... //it's confirmed this is executing
}

bool condition = m_file.bad(); //confirmed this is false
m_file << std::string("hi") << std::endl << std::flush;
condition = m_file.bad(); //true, write failed
I've played around with this a lot, and read a lot of docs, but I am just missing something here. I've confirmed that I do have write access to the file. It also fails in std::ios_base_in|std::ios_base_out|std::ios_base_app mode, which seems to be the recommended way to do this. What's the proper way to do this?

Zakalwe
May 12, 2002

Wanted For:
  • Terrorism
  • Kidnapping
  • Poor Taste
  • Unlawful Carnal Gopher Knowledge

OddObserver posted:

These 2 look portable to C, albeit I am not sure about the idiv --- it's a 64-bit over 32-bit division, isn't it?

Yeah, but the code posted doesn't use the DX register (the reminder)

snack soul
Jul 6, 2005

Chuu posted:

I am doing something really stupid with fstream but cannot figure out what. I want to open a file, read all the contents, and start appending to it.

code:
std::fstream m_file;
m_file.open(filename.c_str(), std::ios_base_in | std::ios_base::out | 
     std::ios_base::ate | std::ios_base::app)
m_file.seekg(std::ios_base_beg);

if(!m_file.is_open()){
	...
}

while(!m_file.eof())
{
	... //it's confirmed this is executing
}

bool condition = m_file.bad(); //confirmed this is false
m_file << std::string("hi") << std::endl << std::flush;
condition = m_file.bad(); //true, write failed
I've played around with this a lot, and read a lot of docs, but I am just missing something here. I've confirmed that I do have write access to the file. It also fails in std::ios_base_in|std::ios_base_out|std::ios_base_app mode, which seems to be the recommended way to do this. What's the proper way to do this?

I don't think ios::app is supposed to be used for input streams (even input-output streams). Try removing that and see if it still fails.

Lexical Unit
Sep 16, 2003

Chuu posted:

code:
std::fstream m_file;
m_file.open(filename.c_str(), std::ios_base_in | std::ios_base::out | 
     std::ios_base::ate | std::ios_base::app)
m_file.seekg(std::ios_base_beg);

if(!m_file.is_open()){
	...
}

while(!m_file.eof())
{
	... //it's confirmed this is executing
}

bool condition = m_file.bad(); //confirmed this is false
m_file << std::string("hi") << std::endl << std::flush;
condition = m_file.bad(); //true, write failed

You can use std::ios::in instead of ios_base to save some typing.

You don't need ate or app or seekg() for this problem, just use ios::in | ios::out.

After the end of your while loop the stream's eof flag will be set. If you want to write to the file you need to clear that flag with m_file.clear();

You don't need to construct a string to stream "hi" to the file, just do m_file << "hi" << ...

You don't need endl and flush as the former will also flush the stream for you.

Instead of if (!m_file.open ()) you can simply use if (!m_file).

To help with testing assumptions you can use assert(). So instead of doing
code:
condition = m_file.bad();
cout << condition << endl;
And then checking the output of your program to see if you get what you expect. You can just do:
code:
assert (!m_file.bad ());
and if the assertion fails it will exit the program and tell you that it failed with the line number.

guenter
Dec 24, 2003
All I want out of life is to be a monkey of moderate intelligence who wears a suit. That's why I've decided to transfer to business school!

Chuu posted:

I am doing something really stupid with fstream but cannot figure out what. I want to open a file, read all the contents, and start appending to it.

code:
std::fstream m_file;
m_file.open(filename.c_str(), std::ios_base_in | std::ios_base::out | 
     std::ios_base::ate | std::ios_base::app)
m_file.seekg(std::ios_base_beg);

if(!m_file.is_open()){
	...
}

while(!m_file.eof())
{
	... //it's confirmed this is executing
}

bool condition = m_file.bad(); //confirmed this is false
m_file << std::string("hi") << std::endl << std::flush;
condition = m_file.bad(); //true, write failed
I've played around with this a lot, and read a lot of docs, but I am just missing something here. I've confirmed that I do have write access to the file. It also fails in std::ios_base_in|std::ios_base_out|std::ios_base_app mode, which seems to be the recommended way to do this. What's the proper way to do this?

Try std::string("hi").c_str() or just "hi". There is no implicit conversion from std::string to char*.

Chuu
Sep 11, 2004

Grimey Drawer

Lexical Unit posted:

After the end of your while loop the stream's eof flag will be set. If you want to write to the file you need to clear that flag with [fixed]m_file.clear();

Thanks for the advice in this thread. This was the issue.

Fehler
Dec 14, 2004

.
What's the best way right now to develop Windows GUI applications in C++? I'd like to have a GUI builder similar to Visual C++ that abstracts away all the low-level stuff, but without spending thousands of dollars...

Is Code::Blocks with wxWidgets any good?

Zakalwe
May 12, 2002

Wanted For:
  • Terrorism
  • Kidnapping
  • Poor Taste
  • Unlawful Carnal Gopher Knowledge

Fehler posted:

What's the best way right now to develop Windows GUI applications in C++? I'd like to have a GUI builder similar to Visual C++ that abstracts away all the low-level stuff, but without spending thousands of dollars...

Is Code::Blocks with wxWidgets any good?

Try http://www.qtsoftware.com/products/platform/qt-for-windows
I personally never write GUI apps, but my friend who's a great C++ programmer swears by it. It's also cross-platform, so if you decide to target Mac OSX or Linux at least the GUI will port quite easily.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Fehler posted:

What's the best way right now to develop Windows GUI applications in C++? I'd like to have a GUI builder similar to Visual C++ that abstracts away all the low-level stuff, but without spending thousands of dollars...

Is Code::Blocks with wxWidgets any good?

Why would you have to spend thousands of dollars? Visual C++ Express is free.

Fehler
Dec 14, 2004

.

Zakalwe posted:

Try http://www.qtsoftware.com/products/platform/qt-for-windows
I personally never write GUI apps, but my friend who's a great C++ programmer swears by it. It's also cross-platform, so if you decide to target Mac OSX or Linux at least the GUI will port quite easily.
Thanks, I'll go check that out.

Avenging Dentist posted:

Why would you have to spend thousands of dollars? Visual C++ Express is free.
Yeah, but isn't that pretty limited in its functionality and/or has some weird license restrictions?

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Fehler posted:

Yeah, but isn't that pretty limited in its functionality and/or has some weird license restrictions?
It doesn't have every feature that, say, Ultimate Professional Team Edition has, but for hobbists and single-person projects it's just fine. Really, if your project really requires 64-bit support or profilers whatever, plunk down the $99 already. (Also, there are no restrictions on using Express for commercial use )

(also, this is where I tell you that Win32 C++ development is infuriating and you really want to use C# instead :v: )

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
Are you a student? You can get Professional Edition for free from Microsoft's DreamSpark.

Morton the Mole
Feb 24, 2005
Paid money to stop lurking.

Mustach posted:

Are you a student? You can get Professional Edition for free from Microsoft's DreamSpark.

This is awesome.

CaptainMcArrr
Oct 4, 2003
PACWANKER HAS HORSE COCK
Hey guys, I'm writing a program in C that takes in options, and input file and (sometimes) an output file from the command line. I'm using getopt as it says to in the spec. I can process the options (like -f, -e etc) okay but I'm having trouble with how to handle the input and output files. The example command line input is:

program -e [-f] [-c] [-o outputfile] inputfile

(the [] denote optional inputs).

Can anyone shed any light?

ChiralCondensate
Nov 13, 2007

what is that man doing to his colour palette?
Grimey Drawer

CaptainMcArrr posted:

Hey guys, I'm writing a program in C that takes in options, and input file and (sometimes) an output file from the command line. I'm using getopt as it says to in the spec. I can process the options (like -f, -e etc) okay but I'm having trouble with how to handle the input and output files. The example command line input is:

program -e [-f] [-c] [-o outputfile] inputfile

(the [] denote optional inputs).

Can anyone shed any light?
When you've finished the
code:
while ((c = getopt(argc, argv, "efco:")) != -1) {
 // use optarg and c
}
loop, getopt has shuffled the argv array so that any non-switch arguments are at the end (but in the same order as they were passed in). The global optind is then the index of the first non-switch argument. E.g. if you run the program with
code:
./a.out -e hurr -f -o out.log blurr
with the arguments defined as you gave them, then when getopt is done you'll have
code:
optind = 4
argv[4] = hurr
argv[5] = blurr
Edit: I missed that you had trouble with -o's argument. In the getopt loop, when you process an "-o" switch, its argument will be in the global optarg.
code:
while ((c = getopt(argc, argv, "efco:")) != -1) {
  switch (c) {
  case 'o':
    printf("the argument to -o is %s\n", optarg);
    break;
  // ... other case statements ...
  }
}

ChiralCondensate fucked around with this message at 12:46 on May 11, 2009

CaptainMcArrr
Oct 4, 2003
PACWANKER HAS HORSE COCK

ChiralCondensate posted:

Helpfulness

Oh man, thanks. That was really helpful, you have no idea how much happier I am now.

FSMC
Apr 27, 2003
I love to live this lie
What's the best way to impliment an undo function for a turn based strategy game? It would be for options like, create unit, move unit, etc. I think I only need it one undo deep.

Currently I'm thinking I'm going to have to make undo functions for every option/function I want to undo and then keep information on each function that is performed that could be undone.

This method doesn't seem that elegent, easy or quick. Also I'll have to edit the undo function everytime I edit the normal function.

Edit: suppose to be in the general programming questions thread, not this one.

agscala
Jul 12, 2008

Keep a track of either all the gamestates or the changes at each step, and when a player chooses to undo, go back in the array/vector/whatever one step

newsomnuke
Feb 25, 2007

Unparagoned posted:

Currently I'm thinking I'm going to have to make undo functions for every option/function I want to undo and then keep information on each function that is performed that could be undone.

This method doesn't seem that elegent, easy or quick. Also I'll have to edit the undo function everytime I edit the normal function.
It's really the only way. For instance, a 'move' action may update the pathfinding database, and this would have to be reset. A 'create' action would allocate memory, and this would have to be deleted. There's no convenient relationship between all the 'do's and 'undo's you'll be performing.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

ultra-inquisitor posted:

There's no convenient relationship between all the 'do's and 'undo's you'll be performing.

There certainly is: a class. I will leave it as an exercise to the reader to design an interface that allows for "do" and "undo" operations.

newsomnuke
Feb 25, 2007

Avenging Dentist posted:

There certainly is: a class. I will leave it as an exercise to the reader to design an interface that allows for "do" and "undo" operations.
I didn't mean implementation, I meant operation. I think he was asking whether C++ had some inbuilt way to perform the inverse of some function. Sure, a good way to implement it would be an Action class with pure virtual do/undo methods.

newsomnuke fucked around with this message at 20:02 on May 11, 2009

FSMC
Apr 27, 2003
I love to live this lie

Avenging Dentist posted:

There certainly is: a class. I will leave it as an exercise to the reader to design an interface that allows for "do" and "undo" operations.

A quick google, suggests you mean something like making a copy of everything in the previous state. Is that right?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Unparagoned posted:

A quick google, suggests you mean something like making a copy of everything in the previous state. Is that right?

What? No (though that's an acceptable solution anyway). I mean "write specific do/undo code for all operations (it's easy) and let the interfaces do the work for you to determine what (if anything) you need to undo".

BigRedDot
Mar 6, 2008

Unparagoned posted:

A quick google, suggests you mean something like making a copy of everything in the previous state. Is that right?

There's two approaches to this. If your total game state can be stored very easily and concisely, say in a single structure, then one way is to simply push a copy of the total game state on to a stack after every action. Then "undo" has nothing to do with any particular action, you simply pop the last game state off and restore it wholesale.

But usually storing a representation of program state takes up too much space, or involves outside resources, making it too complicated for the above method. Then a better way is probably to use Actions. In this case, everything that can be done in the game has to have an associated Action class. The class knows how to "do" the action, but also, knows how to "undo" the action, relative to whatever the current state happens to be. Instead of pushing game state on to a stack, you push Action objects on to a stack. And when you want to undo the last action, you pop off the last Action object and invoke its "undo" method.

FSMC
Apr 27, 2003
I love to live this lie

Avenging Dentist posted:

What? No (though that's an acceptable solution anyway). I mean "write specific do/undo code for all operations (it's easy) and let the interfaces do the work for you to determine what (if anything) you need to undo".

I don't understand :(

Avenging Dentist posted:

I mean "write specific do/undo code for all operations (it's easy)
What do you mean it's easy. Either its specific(I class this as "not easy" in this contex), or is there some kind trick you are trying to get at?

BigRedDot posted:

Then a better way is probably to use Actions. In this case, everything that can be done in the game has to have an associated Action class. The class knows how to "do" the action, but also, knows how to "undo" the action, relative to whatever the current state happens to be. Instead of pushing game state on to a stack, you push Action objects on to a stack. And when you want to undo the last action, you pop off the last Action object and invoke its "undo" method.

I think I kind of get this but let me make sure. Sorry for the poor c++ code below, it's just to get this action idea.

code:
//previously 
move(oldPosition, newPosition);
undoMove();

main()
{
move(oldPosition, newPosition);
undoMove();
}

//new

class move
{
//constructor moves the units position
move(oldPosition, newPosition);
//the deconstructor undos the move
~move();
}

main()
{
move *tempMove=new move;
delete tempMove;
}

Is that the kind of idea, but I'll add each object to a stack, and delete will only be called when I remove the object from the stack...

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Unparagoned posted:

What do you mean it's easy. Either its specific(I class this as "not easy" in this contex), or is there some kind trick you are trying to get at?

How is writing a few lines of code "hard"? Seriously, unless you're making all your actions ridiculously complex, we're talking about 5-10 lines of straightforward code per action type, tops.

Unparagoned posted:

I think I kind of get this but let me make sure. Sorry for the poor c++ code below, it's just to get this action idea.

...

Is that the kind of idea, but I'll add each object to a stack, and delete will only be called when I remove the object from the stack...

Why would you use RAII for action objects? That is just asking for trouble (like when you purge old actions once they're too old to undo). Read what he said again:

quote:

And when you want to undo the last action, you pop off the last Action object and invoke its "undo" method.

BigRedDot
Mar 6, 2008

Not quite. Something more like this:
code:
class Action {
public:
    virtual void Do( ) = 0;
    virtual void Undo( ) = 0;
};

class MoveAction : public Action { 
public:
    Move( int x_offset, int y_offset )
      : x_offset_(x_offset), y_offset_(y_offset) { } 
    void Do( );
    void Undo( );
private:
    int x_offset_;
    int y_offset_;
};

void MoveAction::Do( ) {

    // use x_offset_ and y_offset_ to update the game state

}

void MoveAction::Undo( ) {

    // use x_offset_ and y_offset_ to update the game state "in reverse"

}

void main( ) {

    deque<Action *> history;

    // move the player 2 in the x direction and 3 in the y direction
    Action * a = new MoveAction( 2, 3 );
    a->Do( );
    history.push_front( a );

    // now move the player 7 in the x direction and 1 in the y direction
    Action * b = new MoveAction( 7, 1 )
    b->Do( );
    history.push_front( b );

    // oh wait, we need to undo that last move
    Action * c = history.front( );
    history.pop_front( );
    c->Undo( );
    delete c;

}
Of course, this is just for "Move" actions. You'll need to create subclasses that implement the Action interface for every possible game-state changing action. Also I doubt you'll want a deque, and you'll probably want to use container-safe smart pointers, and you'd definitely want to wrap up the Do-ing/pushing/whatever and popping/Undo-ing/whatever into some abstractions so you aren't repeating the same code over and over.

You should probably think some about what to do when "Undo"-ing is not possble for whatever reason.

You can also decouple your game logic from your do/undo system. MoveAction would then just hold a reference to some model object that actually does all the state updates, instead of doing it itself. Probably overkill for your needs.

Edit: "pubic Action" probably belongs in E/N

BigRedDot fucked around with this message at 21:04 on May 11, 2009

FSMC
Apr 27, 2003
I love to live this lie

Avenging Dentist posted:

Why would you use RAII for action objects? That is just asking for trouble (like when you purge old actions once they're too old to undo). Read what he said again:

Thanks. So do I just have a class and have an undo method in the class. Is it ok to have the do action in the init of the class?


Avenging Dentist posted:

How is writing a few lines of code "hard"? Seriously, unless you're making all your actions ridiculously complex, we're talking about 5-10 lines of straightforward code per action type, tops.

Sorry I got a bit confused. Here is what I though
Me: I would have to write undo functions for each function and update it every time I change the function.
ultra-inquisitor: yep you have to, there is no convenient way of doing it.
Avenging Dentist: There is a convenient way to do it...
So I thought it was all about writing uniquie undo functions. So when you said easy, I though your were talking about some easier way of finding or writing an undo function.


Unparagoned posted:

Currently I'm thinking I'm going to have to make undo functions for every option/function I want to undo and then keep information on each function that is performed that could be undone.

This method doesn't seem that elegent, easy or quick. Also I'll have to edit the undo function everytime I edit the normal function.

ultra-inquisitor posted:

It's really the only way. For instance, a 'move' action may update the pathfinding database, and this would have to be reset. A 'create' action would allocate memory, and this would have to be deleted. There's no convenient relationship between all the 'do's and 'undo's you'll be performing.

Avenging Dentist posted:

There certainly is: a class. I will leave it as an exercise to the reader to design an interface that allows for "do" and "undo" operations.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Unparagoned posted:

Thanks. So do I just have a class and have an undo method in the class. Is it ok to have the do action in the init of the class?

You really shouldn't. All this stuff can get wrapped up anyway so you only interact with it like my_game_state.do(new move_action(player1,left)); and my_game_state.undo();


Unparagoned posted:

Sorry I got a bit confused. Here is what I though
...
I though your were talking about some easier way of finding or writing an undo function.

I'm talking about eliminating the part where you have to manually update your generic "undo anything" function. You shouldn't have to do that if you have a common action interface.

BigRedDot
Mar 6, 2008

Unparagoned posted:

Thanks. So do I just have a class and have an undo method in the class. Is it ok to have the do action in the init of the class?
Just to expand on this. Doing what you suggest limits your options, because it unnecessarily couples performing the action with object creation. What if you have complicated actions that are more easily configured by some builder, over several steps? If you *must* perform the action at object creation, this becomes impossible. If there is no reason to couple, don't couple.

POKEMAN SAM
Jul 8, 2004
Edit: Nevermind, misread.

FSMC
Apr 27, 2003
I love to live this lie

BigRedDot posted:

Just to expand on this. Doing what you suggest limits your options, because it unnecessarily couples performing the action with object creation. What if you have complicated actions that are more easily configured by some builder, over several steps? If you *must* perform the action at object creation, this becomes impossible. If there is no reason to couple, don't couple.

That makes sense.

Thanks BigRedDot and Avenging Dentist. You've been very helpful.

That Turkey Story
Mar 30, 2003

Unparagoned posted:

Thanks. So do I just have a class and have an undo method in the class. Is it ok to have the do action in the init of the class?

Having both do and undo be functions makes it much easier to support undo with redo. When you undo, simply move back in your container without popping the element off, then redo by just moving your iterator forward again and applying redo. If someone undoes several actions and then performs a different action, erase the corresponding elements from your current position in the queue to the end of the container and then push on a new element.

If you have boost, I recommend you use Boost.CircularBuffer for your container, as it is perfect for your situation (fixed maximum size, pops elements off the opposing end as you push once you reach the max).

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
By far the easiest way to implement undo is to maintain (1) a history of the last n actions the user took, together with (2) a copy of your internal state which looks exactly like what things were like n actions ago. Then, if the user asks to undo an operation, you can just restore from the copy and replay the last n-1 actions. The major problem with this approach is that you have to have a full copy of the state; sometimes you can use immutable structures to lower that cost, but sometimes it's just infeasible.

I've found that explicitly-coded undo is usually a recipe for dozens of really subtle bugs, and eventually you'll probably want some operation whose undo implementation will basically require you to copy some fraction of the source data anyway. But your mileage may vary.

Adbot
ADBOT LOVES YOU

DoctorTristan
Mar 11, 2006

I would look up into your lifeless eyes and wave, like this. Can you and your associates arrange that for me, Mr. Morden?
Am I right in thinking that if I have a class with a public static member, I should always initialise it in a .cpp file and not in the header?

In case anyone wants the background, I had a class defined in the following header (no .cpp file):

logisticcell.h
code:
#ifndef LOGISTICCELL_H
#define LOGISTICCELL_H

class LogisticCell {
public:
  static double b;

  ///everything else

};

double LogisticCell::b = 0;

#endif
When I tried to compile my project I got a load of compiler errors complaining about multiple initialisations of the static member b. I think that the problem was that I was creating several .o files depending on logisticcell.h: my target then saw a separate initialisation in each .o and complained.

My solution was to create logisticcell.cpp, move the initialisation into there, then compile logisticcell.o and edit the project dependencies accordingly.

As I said, I've already found a solution to this, but wanted to check that I've done the right thing.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply