Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. A question of indentation!

A question of indentation!

Scheduled Pinned Locked Moved The Lounge
questionc++helptutorial
81 Posts 23 Posters 137 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Nish Nishant

    Len Holgate wrote: The indentation isn't the problem, you're just doing too much in one function The problem is that each of these functions require something from the previous function. For example if fn_1 allocs something, then fn_2 uses that and allocs something else used by fn_3 and so on. On failure at any point I also have to call the respective deallocing PGP functions in reverse order Nish


    Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

    L Offline
    L Offline
    Len Holgate
    wrote on last edited by
    #81

    Nish - Native CPian wrote: The problem is that each of these functions require something from the previous function. For example if fn_1 allocs something, then fn_2 uses that and allocs something else used by fn_3 and so on. On failure at any point I also have to call the respective deallocing PGP functions in reverse order That's the point. If you need to allocate a resource you do so in the constructor, you then use the resource, perhaps to allocate another resource, and release it in the destructor, hence you end up with code like:

    CUsesPGP usesPGP(initStuff);

    CPGPProvider provider("MyProvider");

    CPGPKey key provider.GetKey("Blah");

    CPGPData data(pData, length);

    data.Encrypt(key);

    The c++ class construction order makes sure that the resources are released correctly even if an exception is thrown. Methods throw exceptions so that the user cant ignore errors by default. The code is pretty much self documenting so you dont need huge comment blocks that get out of date. Oh, and it fixes your indentation problem... Len Holgate www.jetbyte.com The right code, right now.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups