Understanding libraries

Hello,for some time now,i've been working on a project involving ciphers and such.
i want to create a library of multiple ciphers that one can call.
but as i have it right now,the ciphers are in their own separate classes,and to call them you need to first make an object of the class,and then use
classname.ciphername() to call it.
how do i make it so that its like other c++ libraries
like
<math> and then i can just use sin();instead of making a math object and doing math.sin() or whatever.how do i do this?
Libraries and classes are unrelated. A library is simply a collection of object files that is searched at link time to satisfy references.

If you don't want to create a class object in order to use functions in that class, you have two choices:
1) Eliminate the use of classes.
2) Make the members of the class static.
e.g.
1
2
3
4
5
6
7
class MYCPIHERCLASS 
{
public: 
  static encrypt_function  ( <args> );
};

MYCIPHERCLASS::encypt_function ( <args>  );


Don't forget you can also use namespaces to isolate your functions.
if i make the members static,what does that change?
will i lose some functionality by setting them to static?
also if i want to make a library how would I go about creating these object collections?
if i make the members static,what does that change?

Making them static means they don't have access to variable members of the class unless those variables are also static.
will i lose some functionality by setting them to static?

Really depends on how your functions are written. If they depend on variables that are members of the class, then this probably is not the best approach.
if i want to make a library how would I go about creating these object collections?

Specifics depend on the IDE you are using. In general, set your project attributes to create a library.

i am using code::blocks
so to create a library like boost is for example,where i can add it to my project by doing #include <libname>
what sort of library should it be?
static,shared or dinamically linked?
Last edited on
what sort of library should it be?

That really depends on what your needs are.
Static libraries are the simplest. The downside is a copy of the library is bound into each executable that uses the library.

Dynamic link libraries have a single image of the library in memory. This is an advantage if you have a lot of programs sharing the same library.



Use a common base class that has a pure virtual method that does the encryption/decryption then implement a factory that allows you to create different types based on an input.

http://en.wikipedia.org/wiki/Factory_method_pattern
http://stackoverflow.com/questions/1306778/c-virtual-pure-virtual-explained

hmm i guess i'll use a static library then.
im still confused about a lot of things,like can i use classes in libraries,and how to actually run libaries.
thank you zeita also,but im not good enough to use those methods yet.
can i use classes in libraries

Yes.

how to actually run libaries

Don't what you mean by "run libraries". You run an executable file, not a library. You build an executable by instructing the linker to search static libraries for any external symbols which have not been found yet.

Topic archived. No new replies allowed.