Search:

Type: Posts; User: serge

Page 1 of 5 1 2 3 4

Search: Search took 0.01 seconds.

  1. Replies
    5
    Views
    9,954

    Thx a lot. I am doing a pure c project atm, and...

    Thx a lot. I am doing a pure c project atm, and it happens to me all the time.
  2. Replies
    5
    Views
    9,954

    But I thought I was passing an element of the...

    But I thought I was passing an element of the array, not the whole array?

    Are you sure your examples compile? This should work



    #include <stdlib.h>

    typedef struct {
    int x;
  3. Replies
    5
    Views
    9,954

    Passing Typedef Struct to a function

    Hello,

    I am a bit confused as to why this code compiles, but is not working, and how to fix it. Can you help? Thx



    #include <stdlib.h>

    typedef struct {
    int x;
  4. Replies
    3
    Views
    4,498

    OK, thank you for the links! I still don't...

    OK, thank you for the links!

    I still don't understand why array of chars are not zeroed, but changing the index to -1 prints the first element.



    My question is it a safe way of doing it if I...
  5. Replies
    3
    Views
    4,498

    Printing an array of string

    Hello,

    why does the function below print the second element "Jim" rather than the first "Hanna"?



    #define PERSONS_NUM 4

    char Names[PERSONS_NUM][40] = {
    "Hanna",
  6. Replies
    2
    Views
    6,525

    Wow, thank you for fixing the code, I really...

    Wow, thank you for fixing the code, I really appreciate it!
  7. Replies
    2
    Views
    6,525

    Pass bitset pattern to constructor

    Hello,

    How can I pass an expression similar to the one I commented out (instead of the binary representation) to the constructor? I would like to make the constructor argument more readable.


    ...
  8. Yes, this works! Thank you!

    Yes, this works! Thank you!
  9. Unique pointer and a vector in the class constructor

    Hello,

    I was mildly surprised when I realized that I cannot initialize the vector directly like in the commented out command, but have to use a default constructor. Surprised because...
  10. Replies
    7
    Views
    11,354

    You mean like this? Engine&...

    You mean like this?



    Engine& operator=(const Engine&) = delete;
    Engine& operator=(Engine&&) = delete;


    The problem I had is if I put this in engine.h
  11. Replies
    7
    Views
    11,354

    I have a follow up issue that I cannot solve even...

    I have a follow up issue that I cannot solve even after checking a few examples on the net. How do I declare the two entities in a header and a cpp file so that function can reach the destructor?...
  12. Replies
    7
    Views
    11,354

    Thanks to both of you. I realized that I don't...

    Thanks to both of you. I realized that I don't need y base class at all, so the problem became simpler. Yes, checking error messages does help in most cases.
  13. Replies
    7
    Views
    11,354

    Simple factory pattern

    Hello,

    how can pass a value to the constructor of the derived structs in this simple factory pattern? thx



    #include <iostream>
    #include <memory>
    #include <vector>
  14. Replies
    1
    Views
    6,246

    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...
  15. void myprint(const short *src[], size_t len) ...

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

    fixed it.
  16. 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]);
    }
  17. 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...
  18. 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))
    {
  19. Replies
    8
    Views
    10,093

    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 =...
  20. Replies
    8
    Views
    10,093

    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>...
  21. Replies
    8
    Views
    10,093

    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...
  22. Replies
    8
    Views
    10,093

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

    Ah..get it! So I need:



    WeaponPtr leftweapon = nullptr;
    WeaponPtr rightweapon = nullptr;
  23. Replies
    8
    Views
    10,093

    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...
  24. Replies
    13
    Views
    24,361

    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
  25. Replies
    13
    Views
    24,361

    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)...
Results 1 to 25 of 120
Page 1 of 5 1 2 3 4