Search:

Type: Posts; User: serge

Page 1 of 5 1 2 3 4

Search: Search took 0.01 seconds.

  1. Replies
    1
    Views
    96

    On the use of inline

    I have read the following statement (partial quote):

    "A reasonable rule of thumb is to not put inline at functions that have more than 3 lines of code in them."

    Does this rule of thumb apply if...
  2. void myprint(const short *src[], size_t len) ...

    void myprint(const short *src[], size_t len)

    fixed it.
  3. But something still is not right, for the two...

    But something still is not right, for the two print calls produce different output:



    void myprint(const short *src, size_t len)
    {
    int i;
    for(i = 0; i < len; ++i) printf("%d\n", src[i]);
    }
  4. OK thanks! So, in my example, the pointer has...

    OK thanks!

    So, in my example, the pointer has been passed correctly but I need to pass the size separately (if I want to do something in the function).

    Just of curiosity, what did my function...
  5. Pass array pointer to function and compute size of array

    Hi,

    why does the function return an incorrect value, here 2 instead of 5?



    #include <stdio.h>

    size_t len(const short (*arr))
    {
  6. Replies
    8
    Views
    247

    But still it should be possible to recast...

    But still it should be possible to recast pointers of unrelated classes, I just can' wrap my head around how:

    Something like this should doable:



    auto A = nullptr;
    if (true) {
    MyType B =...
  7. Replies
    8
    Views
    247

    Another question that came to my mind is why does...

    Another question that came to my mind is why does inserting e.g. weapon in loadout increase the counter of shared pointers (I am using shared)? My types are:



    typedef std::shared_ptr<Weapon>...
  8. Replies
    8
    Views
    247

    Thank you very much! I will rethink the style...

    Thank you very much! I will rethink the style (still very new to cpp, and it shows). Over the past few months, I have learnt so much from all of you in this forum and I greatly appreacite it.

    I...
  9. Replies
    8
    Views
    247

    Ah..get it! So I need: WeaponPtr...

    Ah..get it! So I need:



    WeaponPtr leftweapon = nullptr;
    WeaponPtr rightweapon = nullptr;
  10. Replies
    8
    Views
    247

    An issue with Switch (Scope?)

    Hello,

    I have a function similar to this for character construction (types omitted).

    The switch statement does not work. I though it is an issue of score, but setting curly brackets inside each...
  11. Replies
    13
    Views
    272

    Yes, I made a cut-and-paste error - vector should...

    Yes, I made a cut-and-paste error - vector should be element. The problem that I have is this:

    1. Header (utilities.h)



    #ifndef UTILITIES_H
    #define UTILITIES_H
    #pragma once
  12. Replies
    13
    Views
    272

    To follow up on templates. Putting this function...

    To follow up on templates. Putting this function in the header (along with
    #include <iostream> and
    #include <vector>)



    template <typename T>
    void PrintVector(const std::vector<T>& vector)...
  13. Replies
    13
    Views
    272

    OK, I missed that! So where should the second...

    OK, I missed that! So where should the second line go, given that the type is used in practically the whole program, i.e. certainly downstream of dice.h. Does it need to stay global?
  14. Replies
    13
    Views
    272

    Yes, this works if I put implementations in the...

    Yes, this works if I put implementations in the header, but i would like to have a clean header file and a cpp file with function bodies. The below pattern currently produces an mt19937 error:

    So...
  15. Replies
    13
    Views
    272

    Typedef declaration and header files

    Hi,

    Where should I put typedef that is used in several header files? Putting it in each file causes multiple declaration error, and yet each header file requires a declaration. Should I play...
  16. Ah.. nice! Thx again

    Ah.. nice! Thx again
  17. Arguments of lambda functions need to be local?

    Hello,

    I just wanted to check on this. I have the statement below inside a function (method of Player) that checks that all weapons in the Loadout vector has the same scale as the Player who...
  18. Replies
    7
    Views
    214

    But is it possible to nest a struct like this in...

    But is it possible to nest a struct like this in another struct and pass its argument to the parent struct constructor?
  19. Replies
    7
    Views
    214

    This looks good, thank you! But how what should...

    This looks good, thank you! But how what should be in MyClass (I guess all possible properties), and what should be in its constructor?
  20. Replies
    7
    Views
    214

    The downside is I would need to pass all booleans...

    The downside is I would need to pass all booleans to the constructor (assuming default values of false and a default constructor), even if only few of them need to be set, resulting in a long...
  21. Replies
    7
    Views
    214

    Set of binary properties. Vector of bool?

    Hi,
    I have a very basic question. What is the appropriate data type for what essentially is a collection of bools, taking the value true if a certain property exists? For example, assume there are...
  22. One more question in this vein: Does ...

    One more question in this vein: Does



    DamageLog.clear();


    kill all pointers? I am rewriting the log each game turn instead of updating it (for security). So I am clearing at the beginning...
  23. No, I want each weapon to have a unique key. But,...

    No, I want each weapon to have a unique key. But, you are right, each iteration of the loop moves the same pointer to a new weapon. But how can I insert a copy of pointers to disabled weapons?
    ...
  24. Inserting pointer to an object in vector in a map

    Hi, I would greatly appreciate if you could help me fixing this.

    So, a the simulation runs, different body parts represented by classes declared in the Player Class (e.g. Head, Body, Legs and...
  25. Replies
    8
    Views
    299

    This is awesome, thank you! I knew there is a...

    This is awesome, thank you! I knew there is a trick to pulling that struct outside. Yes, Dial member was not used, sorry about that. Initially I thought I would need it to demonstrate the issue.
Results 1 to 25 of 105
Page 1 of 5 1 2 3 4