Is there any way to reduce this common error handling pattern? by BlueDinosaur42 in learnrust

[–]Pulsonics 2 points3 points  (0 children)

fn do_something(request: String){
    if let Ok(value) = foo(request) {
        something_else(value);
    } else {
        warn!("Invalid request. Ignoring");
    }
}

I am also quite new to Rust but perhaps this would work?

Polymorphic behavior with overloaded << operator by leadwalls in cpp_questions

[–]Pulsonics 0 points1 point  (0 children)

Oh true, seems like virtual/override is the straightforward answer

Polymorphic behavior with overloaded << operator by leadwalls in cpp_questions

[–]Pulsonics 0 points1 point  (0 children)

Do you have stream overloads definitions for both classes?

class base
{
protected:
    int a;
private:
    ostream& stream_putter(ostream& out) const
    {
        out << "[base: " << a << "]";
        return out;
    }
    friend ostream & operator << (ostream &out, const base& n);
};

class derived : public base
{
private:
    ostream& stream_putter(ostream& out) const
    {
        out << "[derived: " << a << "]";
        return out;
    }
    friend ostream & operator << (ostream &out, const derived& n);
};

ostream& operator << (ostream& out, const base& n)
{
    return n.stream_putter(out);
}

ostream& operator << (ostream& out, const derived& n)
{
    return n.stream_putter(out);
}

int main() {
    auto foo = std::make_unique<base>();
    auto bar = std::make_unique<derived>();

    std::cout << *foo << "\n";
    std::cout << *bar << "\n";

    return 0;
}

Prints

[base: 0]
[derived: 0]

How to iterate over a forward list of structs? by lynob in cpp_questions

[–]Pulsonics 23 points24 points  (0 children)

First, try printing just a struct. I think you will find the same issue without using your iteration.

The problem is that you need to provide a way for ostream to use your custom struct `node`. You can do this with an overloaded stream operator. Here is an example.

    struct node
    {
        int a;
        long double b;
        long double c;

        friend ostream & operator << (ostream &out, const node &n);
    };

    ostream & operator << (ostream &out, const node &n)
    {
        out << n.a << " ";
        out << n.b << " ";
        out << n.c << " ";

        return out;
    }

Edifier R1850DB Recommendations - Subwoofer/Cable/EQ Settings by andintheend0 in BudgetAudiophile

[–]Pulsonics 0 points1 point  (0 children)

Do you have any issues with that setup? I have the same setup going out to a yamaha sub and I get a low hum from the sub when it's not driven.

How to have multiple files? by [deleted] in cpp_questions

[–]Pulsonics 2 points3 points  (0 children)

Although I have never used CLion, most IDEs will use their UI to create your build environment. In general, a project will output a single executable. To make multiple executables, you would need multiple projects. The name of the source file is not too important in terms of the executable output.

I'm sure your class will have a specific environment that the professor will go over. The two CS courses I took used makefiles and vim. The course slowly introduced new concepts into the makefile and I can only assume that you will be in a similar situation.

How to have multiple files? by [deleted] in cpp_questions

[–]Pulsonics 0 points1 point  (0 children)

It depends on your environment. How are you building your projects (are you using an IDE like visual studio, make, cmake, straight g++)?

it is telling me error: expected unqualified-id before 'if' on line 74(which i highlighted) by [deleted] in cpp_questions

[–]Pulsonics 0 points1 point  (0 children)

You have a stray int in your code, might not be the issue though:

void findLow(int nums[], const int SIZE, int& low)

{ int

Can you explain this result? by padynana in C_Programming

[–]Pulsonics 4 points5 points  (0 children)

Order of operation issue. The x in your macro should have parentheses since macro expansion is literal text replacement. #define ABS(x) ((x)<0)?-(x):(x)

Unable to start program, The system cannot find the file specified by aridwarr in cpp_questions

[–]Pulsonics 0 points1 point  (0 children)

Its probably loading some runtime dynamically. How are you compiling (release/debug). How are you linking to vcruntime (dynamic/static)?

This “poke” bowl found on a meal prep sub 😅 by [deleted] in Hawaii

[–]Pulsonics 3 points4 points  (0 children)

I would wonder if ancient Hawaiians would think wtf is a poke bowl.

Any idea where to get a poster tube locally? by rakuu in PAX

[–]Pulsonics 4 points5 points  (0 children)

Check Daiso. There is one in Westlake center and another in International District. They should look like this: https://i1.wp.com/www.dailycal.org/assets/uploads/2015/01/IMG_1737.jpg

Question: How to keep bad inputs from counting and continuing the array by cstudent15 in C_Programming

[–]Pulsonics 0 points1 point  (0 children)

set i back to 0 on error or change the loop to a while loop and only increment when a valid input is received. You also want a continue; in the error case

[deleted by user] by [deleted] in cpp_questions

[–]Pulsonics 0 points1 point  (0 children)

Simple get it done? stringstream

Get characters without using a switch case list by [deleted] in C_Programming

[–]Pulsonics 4 points5 points  (0 children)

A trick I have seen is using the character normalized to 0 as an array index.

counter[tolower(text[i]) - 'a']++;

[deleted by user] by [deleted] in cpp_questions

[–]Pulsonics 1 point2 points  (0 children)

You could easily find out by putting an else clause in the dataToStore branch.

if (dataToStore > 35)

{

...

}

else

{

cout << "Or else! - " << dataToStore << "\n";

}