Thx a lot. I am doing a pure c project atm, and it happens to me all the time.
Type: Posts; User: serge
Thx a lot. I am doing a pure c project atm, and it happens to me all the time.
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;
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;
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...
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",
Wow, thank you for fixing the code, I really appreciate it!
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.
...
Yes, this works! Thank you!
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...
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
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?...
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.
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>
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...
void myprint(const short *src[], size_t len)
fixed it.
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]);
}
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...
Hi,
why does the function return an incorrect value, here 2 instead of 5?
#include <stdio.h>
size_t len(const short (*arr))
{
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 =...
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>...
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...
Ah..get it! So I need:
WeaponPtr leftweapon = nullptr;
WeaponPtr rightweapon = nullptr;
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...
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
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)...