#no matching function call

210 messages ยท Page 1 of 1 (latest)

vernal gulchBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

slender fable
#

@lilac galleon

#

wait i compilee it

#

;compile -Wall -Wextra -Wpedantic

#include <cstring>
#include <cstdlib>
#include <cstdio>

enum class Errorstate {
    Value,
    Error
};

class base_Error {
    private:
        char* placeholder;
};

template <typename T, typename E>
union Result {
    T value;
    E err_obj;
};

template <typename T, typename E>
class Expected {
    private:
        Errorstate errorstate;
        Result<T,E> result;
    public:
        void done() const {
            std::printf("DONE");
        }
};

template <typename T, typename E>
Expected<T, E> divide(T a, T b) {
    Expected<T,E> expected_obj;
    return expected_obj;
}

int main() {
    Expected<int, base_Error> expected_obj = divide(3,4);
    expected_obj.done();
}
hearty cometBOT
#
Compiler Output
<source>: In function 'int main()':
<source>:39:52: error: no matching function for call to 'divide(int, int)'
   39 |     Expected<int, base_Error> expected_obj = divide(3,4);
      |                                              ~~~~~~^~~~~
<source>:33:16: note: candidate: 'template<class T, class E> Expected<T, E> divide(T, T)'
   33 | Expected<T, E> divide(T a, T b) {
      |                ^~~~~~
<source>:33:16: note:   template argument deduction/substitution failed:
<source>:39:52: note:   couldn't deduce template parameter 'E'
   39 |     Expected<int, base_Error> expected_obj = divide(3,4);
      |                                              ~~~~~~^~~~~
Build failed
#
Critical error:

You are sending requests too fast!

vernal gulchBOT
#

@slender fable

Please Do Not Delete Posts!

Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.

slender fable
turbid skiff
#

could;mt deduce parameter E

slender fable
#

i specify it in the return argument and i assign the divide(3,4) to it

turbid skiff
#

how is it supposed to?

slender fable
rough barn
#

You only pass T, how is it supposed to figure out E?

#
int main() {
    Expected<int, base_Error> expected_obj = divide<int, base_Error>(3,4);
    expected_obj.done();
}
#

This would do it for example

slender fable
#

like right here

glacial crag
#

That's not good enough

slender fable
#

why not

rough barn
slender fable
glacial crag
#

Here, how about this divide(3, 4);

rough barn
#

Yeah, what if you typed auto:

int main() {
    auto expected_obj = divide<int, base_Error>(3,4);
    expected_obj.done();
}
turbid skiff
#

or ```cpp
template<typename E, typename T>
Expected<T, E> divide(T, T) {}

// ...

auto result = divide<base_Error>(3, 4);

slender fable
#

i dont get it

glacial crag
turbid skiff
#

pretty sure it does

glacial crag
slender fable
#

what does bubble react mean

#

@young skiff

slender fable
#

but doing divide<int,base_Error> is not sufficient either

turbid skiff
#

why not

young skiff
lilac galleon
#

Why not?

young skiff
#

+1 bubbles for you

rough barn
slender fable
#

;compile -Wall -Werror -Wpedantic -Wextra

#include <cstring>
#include <cstdlib>
#include <cstdio>
enum class Errorstate {
    Value,
    Error
};
class base_Error {
    private:
        char* placeholder;
};
template <typename T, typename E>
union Result {
    T value;
    E err_obj;
};
template <typename T, typename E>
class Expected {
    private:
        Errorstate errorstate;
        Result<T,E> result;
    public:
        void done() const {
            std::printf("DONE");
        }
};
template <typename T, typename E>
Expected<T, E> divide(T a, T b) {
    Expected<T,E> expected_obj;
    return expected_obj;
}
int main() {
    Expected<int, base_Error> expected_obj = divide<int, base_Error>(3,4);
    expected_obj.done();
}
hearty cometBOT
#
Compiler Output
<source>: In instantiation of 'Expected<T, E> divide(T, T) [with T = int; E = base_Error]':
<source>:33:69:   required from here
   33 |     Expected<int, base_Error> expected_obj = divide<int, base_Error>(3,4);
      |                                              ~~~~~~~~~~~~~~~~~~~~~~~^~~~~
<source>:28:25: error: unused parameter 'a' [-Werror=unused-parameter]
   28 | Expected<T, E> divide(T a, T b) {
      |                       ~~^
<source>:28:30: error: unused parameter 'b' [-Werror=unused-parameter]
   28 | Expected<T, E> divide(T a, T b) {
      |                            ~~^
<source>: In function 'Expected<T, E> divide(T, T) [with T = int; E = base_Error]':
<source>:30:12: error: 'expected_obj' is used uninitialized [-Werror=uninitialized]
   30 |     return expected_obj;
      |            ^~~~~~~~~~~~
<source>:29:19: note: 'expected_obj' declared here
   29 |     Expected<T,E> expected_obj;
      |                   ^~~~~~~~~~~~
cc1plus: all warnings being treated as er
rough barn
#

๐Ÿ˜•

#

What's not working?

slender fable
#

it doesnt work in godbolt

rough barn
#

Apparently it does

turbid skiff
rough barn
#

Yeah, with -Werror it doesn't work...

#

wow

slender fable
#

i forgot flags its this code

slender fable
slender fable
#
<source>: In instantiation of 'Expected<T, E> divide(T, T) [with T = int; E = base_Error]':
<source>:39:69:   required from here
   39 |     Expected<int, base_Error> expected_obj = divide<int, base_Error>(3,4);
      |    
#

like this error i cant understand rally

rough barn
#

Here's the fixed version:

slender fable
#

but what about the first

rough barn
#

;compile -Wall -Wextra -std=c++20 -Werror

#include <cstring>
#include <cstdlib>
#include <cstdio>
enum class Errorstate {
    Value,
    Error
};
class base_Error {
    private:
        char* placeholder;
};
template <typename T, typename E>
union Result {
    T value;
    E err_obj;
};
template <typename T, typename E>
class Expected {
    private:
        Errorstate errorstate;
        Result<T,E> result;
    public:
        void done() const {
            std::printf("DONE");
        }
};
template <typename T, typename E>
Expected<T, E> divide(T, T) {
    Expected<T,E> expected_obj{};
    return expected_obj;
}
int main() {
    Expected<int, base_Error> expected_obj = divide<int, base_Error>(3,4);
    expected_obj.done();
}
hearty cometBOT
#
Program Output
DONE
glacial crag
turbid skiff
hearty cometBOT
#
Program Output
DONE
slender fable
#

mean

turbid skiff
#

reading c++ errors is a skill lol

rough barn
slender fable
turbid skiff
#

true

#

however

#

it does not say error: there

slender fable
#

i will pay attention to this in the future

#

(i f i dont forgort)

#

idk how wrong my horrible std::expected

#

but isnt this huge overhead

#

to just int error propagation like in C?

#

or whats the benefit of doing the std::expected

#

(yes i am aware my implementation is probably horrible)

#

i dont mind people tell me what would be better too ngl

rough barn
#

What they mean is that this template instantiation is required because the code requested such a type, but because of the unused parameters and the uninitialized variable it complained in that specific template instantiation.

Basically what you need to look at are these white lines on the left. As long as they continue and don't hit white text it's still in the same function (for the error message I extended the main by a variable e2 that you can also see at the top of the error message), which is why we now have 2 different instantiations, both reporting the same issue.

lilac galleon
#

Why does an expected contain a result? Aren't expected and result supposed to be the same?

rough barn
# slender fable where is the e2

There:

int main() {
    auto expected_obj = divide<int, int>(3,4);
    auto e2 = divide<int, base_Error>(3, 4);
    expected_obj.done();
}
neat trout
#

union of actual result and error type

#

The expected class appears to just be a wrapper around that

slender fable
neat trout
#

(In spider man's implemntation i mean)

slender fable
#

i dont know how to get rid of the union

slender fable
lilac galleon
#

You can't.

rough barn
#

std::variant

neat trout
#

std::variant trolol

lilac galleon
#

But you should get rid of Result.

neat trout
#

If you can't see a union, it doesn't exist

lilac galleon
#

It's a poorly named type.

neat trout
#

Yeah you should put it within the exppected class too

slender fable
rough barn
#

๐Ÿ’

slender fable
lilac galleon
#

You can name it other things.

slender fable
neat trout
#

Isnt this what you guys have in rust...

slender fable
neat trout
#

... k

lilac galleon
#

Rust calls this type Result.

slender fable
#

dot gave me the role when i complained that the rust server did not add the emoji i drew for them in paint

neat trout
#

Lol

lilac galleon
#

Haskell calls this type Either.

neat trout
#

Sounds like a variant to me

lilac galleon
#

It's a binary variant.

slender fable
#
template <typename T, typename E>
Expected<T, E> divide(T a, T b) {
    Expected<T,E> expected_obj;
    if (b == 0) {
        expected_obj.errorstate = Errorstate::Error;
        return expected_obj;
    }
    expected_obj.result.value = a/b;
    return expected_obj;
}

int main() {
    Expected<int, base_Error> expected_obj = divide<int, base_Error>(3,4);
    expected_obj.unwrap();
    expected_obj = divide<int, base_Error>(3,0);
    expected_obj.unwrap();
    return 0;
}
#

this print

Program stdout
SUCCEEDED
what happened?
TERMINATION
#

i think this is make sense

#

ez โ“

rough barn
lilac galleon
#

Shouldn't the fact that you can default-construct an expected object be concerning?

slender fable
# rough barn No clue bro. Your old code could only ever print `DONE`.

#include <cstring>
#include <cstdlib>
#include <cstdio>

enum class Errorstate {
    Value,
    Error
};

class base_Error {
    private:
        char* placeholder;
    public:
        void what() const {debug_print("what happened?");}
};

template <typename T, typename E>
union Result {
    T value;
    E err_obj;
};

template <typename T, typename E>
class Expected {
    public:
        Errorstate errorstate;
        Result<T,E> result;
    public:
        void terminate() const {
            debug_print("TERMINATION");
            std::exit(7);
        }
        void success() const {
            debug_print("SUCCEEDED");
        }
        void unwrap() {
            if (errorstate == Errorstate::Error) {
                result.err_obj.what();
                terminate();
            }
            else {
                success();
            }
        }
        T extracta_value() const {
            return result.value;
        }
};

template <typename T, typename E>
Expected<T, E> divide(T a, T b) {
    Expected<T,E> expected_obj;
    if (b == 0) {
        expected_obj.errorstate = Errorstate::Error;
        return expected_obj;
    }
    expected_obj.result.value = a/b;
    return expected_obj;
}

int main() {
    Expected<int, base_Error> expected_obj = divide<int, base_Error>(3,4);
    expected_obj.unwrap();
    expected_obj = divide<int, base_Error>(3,0);
    expected_obj.unwrap();
    return 0;
}
```i just add the unwrap instead of the done
neat trout
lilac galleon
#

So I was wrong.

slender fable
#

someone can tell me whats the worst part of my implementation

#

-# emil โ”

neat trout
#

So i was wrong too

lilac galleon
#

I think you bit off more than you can chew.

neat trout
#

Me or spidey?

slender fable
#

me probably

slender fable
#

i already wrote a hello world program

neat trout
#

Thanks java

slender fable
#

;compile

#include <cstdio>
int main() {
goto Jfbmyzbwsuiyo;Pqydsxkmc:goto Wmviafqorlrwiejqiwdd;Njsyxnuxrh:goto Upfxfhywsjnuz;Jgzshzq:goto Pdrlff;Xqqqfhchtutcap:goto Ncugeiubbeisqlyhhbso;Skiedkrexabfbyxzav:goto Ornqqnv;Hjbjlzdgsfey:goto Rgcjsynbffxdlsnulmmo;Pakmnfkdgcguqhbkgon:goto Nhkecq;Mcgndnegliozlmefoebs:goto Zozcysngirryxusp;Hmspwvkfuyovchrxkg:goto Dwbur;Oolwowcyqzrmfkl:goto Mzarmznkmuj;Ncugeiubbeisqlyhhbso:goto Lukollrgpgh;Xipgzecjiticekknk:goto Njsyxnuxrh;Rpwgxrwzgqibgpvcf:goto Vlxlmflmljhslzdk;Lglottitctvqz:goto Zxlemfjooswuu;Gynwbsleerowwdrbp:goto Ocqjiazala;Oxzgstolvq:goto Jnvdoetdb;Lukollrgpgh:goto Eeewjhbroktzglqj;Eeewjhbroktzglqj:goto Lglottitctvqz;Huzxlaawuvbdtmh:goto Oolwowcyqzrmfkl;Wviljwykdaglnwzgp:goto Lkmiyepzmqmlgtaf;Vlxlmflmljhslzdk:goto Kwunikcicwegjliz;Dwbur:goto Xipgzecjiticekknk;Lkmiyepzmqmlgtaf:goto Gntxkqmb;Kqxdnbdndia:goto Pqydsxkmc;Bkrrbzghqkfrhdw:goto Xqqqfhchtutcap;Khuloudclcdyzru:goto Bxtacr;Jfbmyzbwsuiyo:goto Pakmnfkdgcguqhbkgon;
Fioeqgy:goto Kqxdnbdndia;Glupkyexqbkzly:goto Skiedkrexabfbyxzav;Mzarmznkmuj:goto Ophlnjqvqkh;Xkjjbmcx:goto Jgzshzq;Jnvdoetdb:goto Hjbjlzdgsfey;Wmviafqorlrwiejqiwdd:goto Khuloudclcdyzru;Hrmlj:goto Hmspwvkfuyovchrxkg;Zxlemfjooswuu:goto Hrmlj;Ocqjiazala:goto Xpfblei;Tvzrscowogouubztmo:goto Oxzgstolvq;Upfxfhywsjnuz:goto Huzxlaawuvbdtmh;Buoiymyvem:goto Zevvibusggyuwmwpffj;Xpfblei:goto Buoiymyvem;Nhkecq:goto Ggsyetqimly;Ornqqnv:goto Wviljwykdaglnwzgp;Kwunikcicwegjliz:goto Mcgndnegliozlmefoebs;Bxtacr:goto Glupkyexqbkzly;Zozcysngirryxusp:goto Tvzrscowogouubztmo;Pdrlff:goto Rpwgxrwzgqibgpvcf;Zevvibusggyuwmwpffj:goto Xkjjbmcx;Ggsyetqimly:goto Bkrrbzghqkfrhdw;Rgcjsynbffxdlsnulmmo:printf("Hello Word");goto end;Ophlnjqvqkh:goto Fioeqgy;Gntxkqmb:goto Gynwbsleerowwdrbp;end:return 0;
}
hearty cometBOT
#
Program Output
Hello Word
neat trout
slender fable
rough barn
slender fable
rough barn
#

for sure

slender fable
#

no ofc python

neat trout
#

Why python

#

Why not generate it with c++

rough barn
#

Cause it's faster to generate with Python

slender fable
#

so i only waste 5minute instead of 1 hour

neat trout
#

Not really

slender fable
#

i am trouble in c/c++

#

python for me a litle easier

neat trout
#

Good practice

rough barn
#

I think most people who are equally as skilled in Python as they are in C++ would be a bit faster in Python for this

neat trout
#

Yeah but not significantly so

slender fable
#

i rather not use it

neat trout
#

Your loss

slender fable
#

i am still confused about my divide signature

#

what if instead of my (T a, T b) i have something more complicated

#

a struct X<type1,type2>

#

would my divide need more template parameters then for initialization

#

this would never stop?

neat trout
#

?

slender fable
#

what if i give it instances of

template <typename T1, typename T2>
struct Test {
    T1 first_varialbe;
    T2 second_varialbe;
};
neat trout
#

That will work just fine

slender fable
#

without redefine the signature

template <typename T, typename E>
Expected<T, E> divide(T a, T b) {
  ...
}
neat trout
#

Err... you need to define operator/ for that type

#

Yes

slender fable
neat trout
#

T = Test<T1, T2> in that case

#

Whatever T1 and T2 are

slender fable
#

and change

expected_obj.result.value = a/b;
// to
expected_obj.result.value = a.div(b);
``` or smth?
neat trout
#

?

#

Then it wouldnt work for ints

#

Just define operator/ for Test

slender fable
#

i would require the user to only give it types that have div method implemented

#

that is a worse idea than having / opertaor implemented?

neat trout
#

Yes

#

Because operator/ is standard

#

And already defined for arithmetic types

slender fable
#

ty help @neat trout @rough barn @lilac galleon @sleek prairie ๐Ÿ‘

vernal gulchBOT
#

@slender fable Has your question been resolved? If so, type !solved :)

neat trout
#

!solved

vernal gulchBOT
neat trout
#

Aw

slender fable
neat trout
#

Tf

#

;pin

slender fable
#

Tf?

neat trout
#

What even is that

slender fable
neat trout
#

So you just searh up ;pin ?

slender fable
slender fable
neat trout
#

Huh

slender fable
# neat trout Huh

i only ั€in; my questions that are difficult for me, and that i will want maybe revisit