Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
133 views

(I was making an integer class to replace C's stuff, then this hit me. I wanted an overload for pointer arithmetic.) MSVC and GCC pass without errors or warnings. Compilation: g++ -std=c++2c -fsyntax-...
La Creatura's user avatar
1 vote
1 answer
142 views

Consider the following example: #include <iostream> #include <vector> template<typename T> void foo( T && ) { std::cout << "Common foo!\n"; } template&...
Kaiyakha's user avatar
  • 2,075
6 votes
3 answers
160 views

Consider the following code (live example): #include <memory> struct Base {}; struct Middle : public Base {}; struct Derived : public Middle {}; void foo(Base*); void foo(Middle*); void ...
Igor G's user avatar
  • 2,668
5 votes
1 answer
199 views

I have a working program that compiles successfully in Visual Studio. But trying to port it to GCC/Clang resulted in some compilation errors. Maximally reduced example is as follows: #include <...
Fedor's user avatar
  • 24.7k
4 votes
2 answers
103 views

Why is method(new ExtendsRaw()) ambiguous in the code below? public class Main { private Main() {} static class Generic<T> {} @SuppressWarnings("rawtypes") static ...
Tomer Aberbach's user avatar
1 vote
1 answer
67 views

I'm am testing out the C#/Win32 project so I can call Win32 Setup API functions with automatically generated PInvoke wrappers. I am unable to make my code call the correct overload of one of the ...
Joe's user avatar
  • 7,194
4 votes
1 answer
76 views

Ok this might be a bit difficult to explain: I want to call a function hello that has an overload for either an rvalue or an lvalue ref of type Json. This Json object is converted from a JsonKey using ...
glades's user avatar
  • 5,356
6 votes
1 answer
104 views

Look at this code (godbolt): template <typename ...T> void func(const char *it, T &&...t) {} template <typename A, typename B> void func(A &&a, B &&b) {} int main(...
geza's user avatar
  • 30.5k
0 votes
1 answer
95 views

Function overload resolution doesn't take return type into account, however I came across a piece of code on cppreference SFINAE aside, how is overload resolution happening here: #include <iostream&...
san216's user avatar
  • 95
14 votes
3 answers
1k views

I wrote a function with two overloads - one for a single pointer and one for a vector of pointers. At some point in the code I wanted to pass an empty vector to the function and used {} as the ...
michael3.14's user avatar
0 votes
1 answer
133 views

I'm trying to understand the following language from cppreference.com (emphasis mine): Each type of standard conversion sequence is assigned one of three ranks: Exact match: no conversion required, ...
user3188445's user avatar
  • 4,980
1 vote
1 answer
80 views

Can someone please explain which language rules are in play in the following example: #include <iostream> #include <type_traits> template<typename T> struct Holder{ T val; ...
Ferenc Janky's user avatar
2 votes
0 answers
65 views

I have two methods in my EF context class, one is an override and one is a new member like this: public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default) ......
Tanveer Badar's user avatar
7 votes
2 answers
154 views

#include <cstdio> #include <string> class A { std::string data; public: A() = default; explicit A (const char* data) : data(data) {} operator const char* () const; ...
Martin Horský's user avatar
2 votes
1 answer
122 views

In the following test program, struct B has two member functions f, which can be called using B{}.f(): one ordinary f() and another with explicit object f(this A). struct A { int f() { return 1; } ...
Fedor's user avatar
  • 24.7k
2 votes
1 answer
105 views

This question is based on previous SO discussion (which was affected by non-compliant compilers). So I'm using the latest c++23 released versions of gcc/clang/MSVC. Here is a simple test with ...
Gene's user avatar
  • 754
3 votes
1 answer
2k views

I can't wrap my head around the second impl block. In my understanding, impl is typically used to implement a trait/methods on a concrete type like a struct. However, what does it mean to implement ...
Code learner's user avatar
6 votes
3 answers
317 views

How is this expected to work? struct S {}; void foo(volatile S&); void foo(S); int main() { volatile S v; foo(v); } Compilers disagree on it: MSVC accepts the code, while Clang and GCC ...
Dr. Gut's user avatar
  • 3,335
2 votes
2 answers
120 views

I just wrote following simple code but it doesnt compile: #include <iostream> #include <string> class Obj{ public: std::string name = "Name"; std::string l_name = "...
Qwe Qwe's user avatar
  • 557
0 votes
2 answers
92 views

Can the semantics of a well-formed C++ translation unit depend on the presence of a function or function template declaration that is never used? By "used", I mean it is selected by ...
Scott McPeak's user avatar
  • 13.8k
8 votes
3 answers
491 views

Here is a piece of code that tries to provide a pointer to an overloaded function to another function that can accept a value of any type: template <typename T> void AcceptAnything(T&&); ...
jacobsa's user avatar
  • 7,817
2 votes
1 answer
134 views

In the following program template function f calls overloaded template function p and one of the overloads is declared after f, but as far as I understand it must be found at the point of ...
Fedor's user avatar
  • 24.7k
30 votes
1 answer
2k views

In the following example, 0 behaves in a special way: it chooses a different overload than one would expect for one example function call. I would like to know why. My understanding is also below. #...
toxic's user avatar
  • 600
1 vote
1 answer
114 views

I'm trying to create a overload for a function with variadic template arguments for a type and all its possible derivates. Naively i tried with just one overload and the base class as the first ...
ridilculous's user avatar
2 votes
1 answer
76 views

In the example below, why does the last one calls the function overload with std::function as parameter? #include <iostream> #include <functional> #include <memory> template <...
auzn's user avatar
  • 695

1
2 3 4 5
17