1,085 questions
8 votes
1 answer
127 views
Forward declaration in global module fragment
I have a template<int d> class Monomial and a template<int d> class Polynomial. Polynomial<d> owns a std::map<Monomial<d>, double>. I would like to create a member ...
Advice
2 votes
4 replies
249 views
Can function-local class be defined in the global scope?
Any C++ class can be first forward declared, and defined only later in the program. Are function-local classes an exception from this rule? Please consider a simplified program: auto f() { struct ...
7 votes
1 answer
202 views
Visibility of C++ nested class complete definition in the presence of forward declarations
In C++, forward declarations introduce an incomplete type. Incomplete types can be used to declare pointers, but they cannot be used to initialize values or access members because the complete ...
2 votes
1 answer
210 views
What are good practice for forward declaration of nlohmann::json in C++?
I am working on a project in my spare time, and have been told to forward declare whenever possible. My project includes nlohmann::json across several files, so I thought to try and forward declare it ...
3 votes
1 answer
131 views
Reduce boilerplate for explicit templates instantiations in .cpp file
In order to hide template function definition in .cpp file, while having the forward declaration in a header file (function is used by a class template), the template has to be instantiated in order ...
5 votes
1 answer
86 views
Error when repeating forward declaration with default template argument
When repeating the declaration of a template class with defaulted argument, I get an error: <source>:12:23: error: redefinition of default argument for 'class<template-parameter-1-2>' ...
1 vote
1 answer
56 views
Confusion on Struct forward declaration
I have this code on ADT specification of a node typedef int ElType; typedef node* Address; typedef struct node{ ElType info; Address next; } Node; Does it going to be the same if i do this? ...
2 votes
2 answers
92 views
Elfutils library forward declaration error
I'm currently working in C++ with the elfutils library and I'm struggling with something that should be obvious. Here is a MCVE that shows my problem: file.cpp struct Elf64_Sym; #include <elf.h>...
5 votes
2 answers
161 views
Incorrect return type allowed for forward declared function: Why is there no linker error here?
$ g++ --version Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1 Apple clang version ...
-1 votes
1 answer
679 views
Forward Class Declaration in Python in a Dictionary
This is a question that has been debated many times in this forum. There is however a case that i have not seen a good way to solve. from __future__ import annotations class ClassA: pass class ...
1 vote
1 answer
94 views
Python avoid mypy fails when redefining a class from another class in mutual reference
Consider a pair of classes which represent the same thing in Python and each implements a method that converts one to the other. As an example consider transforming from cartesian to polar coordinates ...
3 votes
1 answer
117 views
is a class declaration before base-clause a valid forward declaration?
I'm not sure if my question title is the most appropriate and I will change it happily to something clearer if I get adequate suggestion. In a C++ video whose subject is not the one here, I saw this ...
0 votes
1 answer
164 views
Correct way to forward declare structs? [duplicate]
Let's suppose I want to declare structs A and B struct A{ B toB(){ return B(); } }; struct B{ A toA(){ return A(); } }; I'll get an error that type B is undefined main.cpp:2:2: error: ...
0 votes
0 answers
47 views
Error when using data-member of a class inside a friend function defined in another class
So, here I have two classes, one has the friend function definition and the other a private data member. I want to access the private data member with the friend member function but it gives me an ...
0 votes
1 answer
277 views
Declare procedures prototypes in nim
I am trying understand how I can declare, in a nim source, different procedures that call each other, as it sounds like the compiler expects all calls to come after the declaration, but the procedures ...