1,085 questions
8
votes
1
answer
121
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 ...
7
votes
1
answer
194
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 ...
3
votes
1
answer
130
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 ...
1
vote
1
answer
55
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?
...
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
vote
1
answer
91
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 ...
0
votes
1
answer
162
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
1
answer
274
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 ...
-1
votes
1
answer
191
views
Forward Declaration (PIMPL) for External Libraries also used in Method Declarations?
I have looked at a significant number of posts regarding forward declarations/PIMPL, but haven't quite managed to get it to work with the external libraries I'm using. I want to create a shared ...
0
votes
0
answers
156
views
Simple forward declaration compiles with g++ but not clang
As for a minimally reproducible example, say I have the following class A defined in a header file a.h:
// file a.h
#include <cstdio>
class A {
private:
int val;
public:
A(int aVal) { ...
4
votes
0
answers
199
views
If I forward declare a function template, may I put the definition after the calling site and not explicit instantiate it at all?
In a header file of a large project, I have to forward declare a function template before the calling site. The code boils down to this:
//H1.h
#pragma once
template <typename>
void f();
...
-2
votes
2
answers
137
views
std::unique_ptr<incomplete_type> without custom deleter
The following https://godbolt.org/z/5qd8WbYz9 doesn't work and after reading the duplicate I thought I would have to define an custom deleter
However, I managed to get it working https://godbolt.org/z/...
3
votes
3
answers
538
views
Forward declaring a static variable in C++
I run into the following problem and idk if it can be solved in an elegant way:
I need to statically initialize an interface wifi and sntp in main. I can't do it in global space because they are ...
3
votes
1
answer
109
views
Forward declaring a specific template instance
I have a template that is just that - a very basic class template; something like:
Tmpl.h
template <typename Base>
class Tmpl: public Base
{
public:
Tmpl(): Base()
{
this->...
1
vote
1
answer
170
views
How to initialize a forward-declared class in C++ [duplicate]
I have two classes, A and B, which depend on each other:
class A {
public:
B* b;
A() {
b = new B();
}
};
class B {
public:
A* a;
B() = default;
};
This code will not ...
-1
votes
3
answers
418
views
Defining a nested class out of line in C++
Sorry if this has been asked before; I found similarly titled questions, but none of them focused on the same aspects I'm having trouble with.
There's a class A, and a class B that should only be ...
0
votes
1
answer
75
views
Two files including each other causes errors that cannot be fixed by forward declaring
So, read clearly...
// scene.h
#include "Entity.h"
class Scene
{
public:
Entity createEntity() {
return Entity(this);
}
};
So, that was the Scene class, then we've got the ...
2
votes
1
answer
193
views
Why can I reference a member of an enum that is only forward declared [closed]
For example, given the following:
// enum.h
enum class TestEnum: int {
ONE,
TWO,
THREE
};
// function.h
enum class TestEnum: int;
int TestFunction(TestEnum te = TestEnum::THREE);
// ...
1
vote
1
answer
310
views
Forward declaration in namespace
Consider the following scenario:
"A.cpp":
void fun() { std::cout << "fun() global\n"; }
"B.cpp":
namespace N
{
void f()
{
std::cout << "...
3
votes
1
answer
259
views
C++: struct forward declaration of anonymous struct causes "conflicting declaration"
I have got this hpp file:
struct rte_spinlock_t;
class A {
public:
void init();
private:
rte_spinlock_t* spinlock;
};
and the corresponding cpp file:
#include "A.hpp&...
2
votes
1
answer
196
views
Is it legal to use a different class-key in a declaration and the definition of a class-name?
Does the standard (as of C++20) explicitly or implicitly allow using a different class-key when (forward-)declaring a class-name than when defining it?
For the purpose of this question class-key shall ...
0
votes
0
answers
999
views
C++ forward declaration not working as expected in class [duplicate]
I am doing a project where I recreate Pokémon in C++ and currently I am in the process of implementing moves.
My implementation is currently:
#pragma once
class Pokemon;
class MoveBase
{
public:
...
0
votes
1
answer
146
views
How to provide type annotations in case of circular dependency in different files in Python?
Please consider the following working code
from __future__ import annotations
class A(object):
def __init__(self, val: int):
self.val = val
@property
def b(self) -> B:
...
1
vote
1
answer
613
views
Forward declaring a template type parameter
I see this question has been discussed in various places, e.g. here,here,here and here .But, i have still not been able to relate to the questions aforementioned.
My situation:
I am trying to ...
2
votes
2
answers
132
views
If I declare a function with extern "C", should I also define it that way?
In my header file, foo.h, I have:
#ifdef __cplusplus
extern "C" {
#endif
int foo(int x);
#ifdef __cplusplus
}
#endif
Now, in foo.cpp, should I also use extern "C", and define:
#...