Author Topic: A few C++ questions  (Read 4504 times)

0 Members and 1 Guest are viewing this topic.

Offline Scipi

  • Omni Kitten Meow~ =^ω^=
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1547
  • Rating: +192/-3
  • Meow :3
    • View Profile
    • ScipiSoftware
A few C++ questions
« on: October 13, 2010, 11:27:35 pm »
How do you add libraries to where you can just include the .h file? Im trying to link with allegoro for gui's and graphics and stuff.

And what exactly are pointers good for. I know what they do and what they are but what can they do that variables can't?

Thx.

Imma Cat! =^_^= :3 (It's an emoticon now!)
Spoiler For Things I find interesting:
Spoiler For AI Programming:
Spoiler For Shameless advertising:

Spoiler For OldSig:





Spoiler For IMPORTANT NEWS!:
Late last night, Quebec was invaded by a group calling themselves, "Omnimaga". Not much is known about these mysterious people except that they all carried calculators of some kind and they all seemed to converge on one house in particular. Experts estimate that the combined power of their fabled calculators is greater than all the worlds super computers put together. The group seems to be holding out in the home of a certain DJ_O, who the Omnimagians claim to be their founder. Such power has put the world at a standstill with everyone waiting to see what the Omnimagians will do...

Wait... This just in, the Omnimagians have sent the UN a list of demands that must be met or else the world will be "submitted to the wrath of Netham45's Lobster Army". Such demands include >9001 crates of peanuts, sacrificial blue lobsters, and a wide assortment of cherry flavored items. With such computing power stored in the hands of such people, we can only hope these demands are met.

In the wake of these events, we can only ask, Why? Why do these people make these demands, what caused them to gather, and what are their future plans...

Offline Empyreal

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 18
  • Rating: +5/-0
    • View Profile
Re: A few C++ questions
« Reply #1 on: October 13, 2010, 11:55:49 pm »
I'm not sure I completely understand your first question, but if I do the answer will vary depending on which linker you're using.  If you're compiling and linking in one step with g++, it'll look something like:
g++ -o progname progname.cpp -lallegro
The form for that last argument is -lNAME_OF_LIBRARY.

Pointers store the address of a variable, structure, etc. The most straightforward usage of them is to give functions access to large amounts of data without the tremendous (in some cases) overhead of actually passing all of that data.

Offline Scipi

  • Omni Kitten Meow~ =^ω^=
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1547
  • Rating: +192/-3
  • Meow :3
    • View Profile
    • ScipiSoftware
Re: A few C++ questions
« Reply #2 on: October 15, 2010, 01:52:07 am »
Ok think I see the use of pointers a little.

I was really talking about how I would go about adding a library so I could just include it from anywhere with #include.

Imma Cat! =^_^= :3 (It's an emoticon now!)
Spoiler For Things I find interesting:
Spoiler For AI Programming:
Spoiler For Shameless advertising:

Spoiler For OldSig:





Spoiler For IMPORTANT NEWS!:
Late last night, Quebec was invaded by a group calling themselves, "Omnimaga". Not much is known about these mysterious people except that they all carried calculators of some kind and they all seemed to converge on one house in particular. Experts estimate that the combined power of their fabled calculators is greater than all the worlds super computers put together. The group seems to be holding out in the home of a certain DJ_O, who the Omnimagians claim to be their founder. Such power has put the world at a standstill with everyone waiting to see what the Omnimagians will do...

Wait... This just in, the Omnimagians have sent the UN a list of demands that must be met or else the world will be "submitted to the wrath of Netham45's Lobster Army". Such demands include >9001 crates of peanuts, sacrificial blue lobsters, and a wide assortment of cherry flavored items. With such computing power stored in the hands of such people, we can only hope these demands are met.

In the wake of these events, we can only ask, Why? Why do these people make these demands, what caused them to gather, and what are their future plans...

Offline Empyreal

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 18
  • Rating: +5/-0
    • View Profile
Re: A few C++ questions
« Reply #3 on: October 15, 2010, 02:11:14 am »
Pointers can be confusing at first, but once you use them a few times, you'll see they can be really useful.  In C++, the need to use pointers is not as great as it is in C thanks to classes.

Okay, I see.  #include isn't used to include libraries.  It is used to include header files.  For simplicity's sake, let's just say header files contain function prototypes. These prototypes are needed by the compiler to produce the object file.  All the compiler does is make sure you're passing the correct types of arguments and using the return value appropriately.  The linker is responsible for connecting these references to the actual functions.

So, simply put: you cannot include libraries at all.  You have to include the relevant header files and link the library.

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: A few C++ questions
« Reply #4 on: October 15, 2010, 02:56:23 am »
In visual studio, you can import a library from a header file like this:

Code: [Select]
#pragma comment (lib, "mylibrary.lib")
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: A few C++ questions
« Reply #5 on: October 15, 2010, 03:28:10 am »
Pointers can be confusing at first, but once you use them a few times, you'll see they can be really useful.
Yeah they took me quite a bit to understand in Axe Parser x.x

Offline Scipi

  • Omni Kitten Meow~ =^ω^=
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1547
  • Rating: +192/-3
  • Meow :3
    • View Profile
    • ScipiSoftware
Re: A few C++ questions
« Reply #6 on: October 15, 2010, 11:49:19 pm »
Yeah I use MinGW as my compiler. Im still having problems with using allegro in my programs. I use Code::Blocks with MinGW. I think I might not have the dll file required. Though I haven't found any DL's.

Imma Cat! =^_^= :3 (It's an emoticon now!)
Spoiler For Things I find interesting:
Spoiler For AI Programming:
Spoiler For Shameless advertising:

Spoiler For OldSig:





Spoiler For IMPORTANT NEWS!:
Late last night, Quebec was invaded by a group calling themselves, "Omnimaga". Not much is known about these mysterious people except that they all carried calculators of some kind and they all seemed to converge on one house in particular. Experts estimate that the combined power of their fabled calculators is greater than all the worlds super computers put together. The group seems to be holding out in the home of a certain DJ_O, who the Omnimagians claim to be their founder. Such power has put the world at a standstill with everyone waiting to see what the Omnimagians will do...

Wait... This just in, the Omnimagians have sent the UN a list of demands that must be met or else the world will be "submitted to the wrath of Netham45's Lobster Army". Such demands include >9001 crates of peanuts, sacrificial blue lobsters, and a wide assortment of cherry flavored items. With such computing power stored in the hands of such people, we can only hope these demands are met.

In the wake of these events, we can only ask, Why? Why do these people make these demands, what caused them to gather, and what are their future plans...