Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 208 209 [210] 211 212 ... 297

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 70515 times)

Skyrunner

  • Bay Watcher
  • Zaaap~
    • View Profile
    • Winterer
Re: if self.isCoder(): post() #Programming Thread
« Reply #3135 on: October 18, 2012, 09:14:55 am »

Double post.
Logged

Her desire to shank humans clearly stems from the martian combat-beast side of her family...
Grand Unified Model programming collab / Erosion sim? ;3 (DirectX required)

alway

  • Bay Watcher
  • Edit all the posts!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3136 on: October 18, 2012, 09:45:57 am »

The 2005's are caused by putting those function definitions in the .h file. It doesn't like it when the .h has both the function declaration in the class definition and the function definition. Move those 2 functions to a .cpp which includes that .h file.
« Last Edit: October 18, 2012, 09:55:26 am by alway »
Logged

Skyrunner

  • Bay Watcher
  • Zaaap~
    • View Profile
    • Winterer
Re: if self.isCoder(): post() #Programming Thread
« Reply #3137 on: October 18, 2012, 09:49:22 am »

Weird...  ??? Do all functions do that, or is that a special case? I'm sure I've defined and declared a function in a single .h file more than once...
BTW, I'm not at my PC, so I'll have to get back on that in about 16 hours xD

Also, any help on the extern POD PODS error? Dx
C++'s incomprehensible errors are the worst.
Logged

Her desire to shank humans clearly stems from the martian combat-beast side of her family...
Grand Unified Model programming collab / Erosion sim? ;3 (DirectX required)

alway

  • Bay Watcher
  • Edit all the posts!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3138 on: October 18, 2012, 09:56:09 am »

That's something member functions do; if you are using a more c-like syntax without putting things in classes, it works just fine.

As for the 2001 error, I don't think you are using extern correctly. From what I recall, extern says 'there is some variable with this name which is in the global scope of another file.' Which requires there to be a 'PODS POD;' in the global scope of another file (a .cpp in particular, IIRC). If one doesn't exist without an 'extern' marker, the linker then gets confused, as it's looking for a non-extern version to use as sort of the master-variable all of them are set to. If you remove 'extern' from the version in main, I suspect that error would go away, assuming I remember how they work correctly.

Edit: seems I don't recall correctly; may be something else.
Edit2: seems I do recall correctly; set up similar test code, got the same error, then fixed it by removing the 'extern' from the declaration in main.

The test code:
Code: ("cla.cpp") [Select]
#include "stru.h"

extern stru s;
Code: ("stru.h") [Select]
struct stru
{
int n;
char* str;
};
Code: ("main.cpp") [Select]
#include "stru.h"
#include <iostream>
using namespace std;

extern stru s;

int main()
{
cout<<s.n<<endl;
return 0;
}
This throws LNK2001 error; remove the 'extern' from one of the two 'stru s,' and the errors go away, while leaving the 2 'stru s' as the same variable (verified by a function in cla.cpp changing its value; not shown).
« Last Edit: October 18, 2012, 10:32:14 am by alway »
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3139 on: October 18, 2012, 11:32:33 am »

Yeah, I did that last thing, defined the necessary defines in the top of the files (it's just a .h and .c), and it compiles fine, but I still get a linker error about "undefined reference to function triangulate(<params here>). I do get the .o file, though.

Make sure that, when using a C header in C++ code, you do the following:

Code: [Select]
extern "C" {
#include "c_header.h"
}

I don't know if that will fix your linker problem, but it's worth a shot.
*D'OH*
Thanks.

Skyrunner, i think it's because you redefine POD in the main. Try removing PODS POD from the main function, and the extern from the global declaration before that.
Logged

A friend is just a stranger with beer.

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3140 on: October 18, 2012, 12:47:32 pm »

I need some help understanding build options in CodeBlocks related to the linker. I have two projects: Hello World and TestLibrary, and I want to link TestLibrary with Hello world.

In Search directories --> Linker, I put "..\lib\", and in Linker settings --> Link libraries: I put "TestLibrary". I get a compile error: "cannot find -lTestLibrary".

However, if I don't put anything in Search directories --> Linker, and put the full path of the library in Linker settings --> Link libraries: ("..\lib\TestLibrary.a"), it works fine.

I've tried lots of things, like changing "TestLibrary" to "TestLibrary.a" in the first case. Can anyone explain what's going on?
Logged
dreadmullet has been ecstatic lately. He has lost a friend to tragedy recently. He was forced to endure the decay of a friend. He sustained major injuries recently. He complained about thirst lately. He has witnessed death. He was disgusted by a miasma recently. He dined in a legendary dining room recently.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3141 on: October 18, 2012, 01:30:27 pm »

I need some help understanding build options in CodeBlocks related to the linker. I have two projects: Hello World and TestLibrary, and I want to link TestLibrary with Hello world.

In Search directories --> Linker, I put "..\lib\", and in Linker settings --> Link libraries: I put "TestLibrary". I get a compile error: "cannot find -lTestLibrary".

However, if I don't put anything in Search directories --> Linker, and put the full path of the library in Linker settings --> Link libraries: ("..\lib\TestLibrary.a"), it works fine.

I've tried lots of things, like changing "TestLibrary" to "TestLibrary.a" in the first case. Can anyone explain what's going on?

Try naming the library file "libTestLibrary.a". When you specify a library as "a", ld (GCC's linker) looks for a file named "liba.a". Specifying the full path in the library list makes it override that behavior and look for the exact file you gave it.

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3142 on: October 18, 2012, 01:34:43 pm »

That worked! I used "..\lib" and "libTestLibrary" in the build options. Thanks.


Edit: Does this mean that I can only use the Search directories for the linker if the '.a's are prefixed with "lib"?
« Last Edit: October 18, 2012, 01:37:10 pm by dreadmullet »
Logged
dreadmullet has been ecstatic lately. He has lost a friend to tragedy recently. He was forced to endure the decay of a friend. He sustained major injuries recently. He complained about thirst lately. He has witnessed death. He was disgusted by a miasma recently. He dined in a legendary dining room recently.

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3143 on: October 18, 2012, 08:44:56 pm »

Whoa... I spent the good chunk of a few days trying to get Qt to work properly with Visual Studio. Bad idea. I could get the basics of a window, but I couldn't get buttons to work with Qt's complex build system. So I discovered that CodeBlocks has a Qt4 project template, and I created a new project with that and took 2 minutes to set it up, and it worked perfectly and built instantly. Why did I ever doubt CodeBlocks...

This has happened to me so many times with Visual Studio. I try to get some library working that was originally made for Linux. But then it takes me days to figure it out, or most of the time I give up after hours of googling. I think I'll switch to CodeBlocks and MinGW from now on.
Logged
dreadmullet has been ecstatic lately. He has lost a friend to tragedy recently. He was forced to endure the decay of a friend. He sustained major injuries recently. He complained about thirst lately. He has witnessed death. He was disgusted by a miasma recently. He dined in a legendary dining room recently.

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #3144 on: October 18, 2012, 09:13:31 pm »

Blurg. I guess writing thorough unit tests for my shit is good. In java, the supplementary collections returned by the methods of collections do not use their parent classes methods! but directly deal wit the underlying data structures.

What this means is that calling MyCustomCollection.keySet().remove(key) DOES NOT call MyCustomCollection.remove(key)... so any logic you have to perform when removing something from your collection? gets shit on. You have to create an inner class to handle each of these collections f you have special logic that must execute on insert/removal.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Putnam

  • Bay Watcher
  • Legendary+1 Modder
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3145 on: October 18, 2012, 09:31:48 pm »

Why do you have both collatznumber and collatzednumber? collatznumber is read in from standard input, has its value assigned to collatzednumber, and then is never used again. You can combine those two variables into one.

Kept the rest of the post in mind and used it all, but this I was confused about for a bit before I remembered that I wanted to write a program that will do the collatz process on every number up until a number of the user's choosing and, at the end, output the number that took the longest to collatz. Naturally, that would probably require an entirely rewritten program, so the "collatznumber" variable is kind of a zombie :P

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3146 on: October 18, 2012, 10:05:32 pm »

Why do you have both collatznumber and collatzednumber? collatznumber is read in from standard input, has its value assigned to collatzednumber, and then is never used again. You can combine those two variables into one.

Kept the rest of the post in mind and used it all, but this I was confused about for a bit before I remembered that I wanted to write a program that will do the collatz process on every number up until a number of the user's choosing and, at the end, output the number that took the longest to collatz. Naturally, that would probably require an entirely rewritten program, so the "collatznumber" variable is kind of a zombie :P

Warning kids, don't let your variables eat your brains!

alway

  • Bay Watcher
  • Edit all the posts!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3147 on: October 18, 2012, 11:29:46 pm »

More from my program:

This is how babby river is made!

Approximately 1 hour of run time which I timelapsed into 2 minutes @ 30fps, with each frame being 1 second.
Logged

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3148 on: October 19, 2012, 01:57:58 am »

What this means is that calling MyCustomCollection.keySet().remove(key) DOES NOT call MyCustomCollection.remove(key)... so any logic you have to perform when removing something from your collection? gets shit on. You have to create an inner class to handle each of these collections f you have special logic that must execute on insert/removal.
Why would you expect anything different? You're removing data from an entirely separate object (which just happens be created by another object). Having the mutation of the set affect the general collection seems dangerous (in general) and inconsistent with Java's general trend to idiot-proof things. My question is, where would you only have access to a set containing the keys where you wouldn't have access to the original collection? Alternatively, why would you need to remove it from the set of keys and have that update the original collection when you could just remove it directly from the collection?
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #3149 on: October 19, 2012, 07:44:33 am »

why? because that is the contract defined for the various collections interfaces. the keyset and other such collections are supposed to be baacked by the original collection..
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.
Pages: 1 ... 208 209 [210] 211 212 ... 297