Skip to main content
Filter by
Sorted by
Tagged with
8 votes
1 answer
132 views

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 ...
BenPol's user avatar
  • 93
Advice
2 votes
4 replies
253 views

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 ...
Fedor's user avatar
  • 24.8k
7 votes
1 answer
205 views

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 ...
Connor Lawson's user avatar
2 votes
1 answer
232 views

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 ...
Lukas Kronholm's user avatar
3 votes
1 answer
133 views

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 ...
Sergey Kolesnik's user avatar
5 votes
1 answer
86 views

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>' ...
Sergey Kolesnik's user avatar
1 vote
1 answer
56 views

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? ...
Awafi's user avatar
  • 11
2 votes
2 answers
92 views

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>...
Forbinn's user avatar
  • 85
5 votes
2 answers
161 views

$ 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 ...
ps_'s user avatar
  • 148
-1 votes
1 answer
681 views

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 ...
Maeglin's user avatar
  • 47
1 vote
1 answer
94 views

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 ...
roschach's user avatar
  • 9,646
3 votes
1 answer
117 views

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 ...
Oersted's user avatar
  • 3,904
0 votes
1 answer
165 views

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: ...
BlobKat's user avatar
  • 320
0 votes
0 answers
47 views

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 ...
Tobías Milano's user avatar
0 votes
1 answer
283 views

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 ...
GiMS_Pang's user avatar
0 votes
0 answers
193 views

I'm using code::bloks with this simple project: a.cpp : int get() {return 0;} main.cpp : int get(); int main() { int x = get(); return 0; } at compile I get : undefined reference to 'get()' ...
stupiddevil's user avatar
-1 votes
1 answer
191 views

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 ...
RPH's user avatar
  • 129
11 votes
4 answers
1k views

The code snippet below demonstrates a real issue I faced recently in my program: #include<vector> class A; void f( const std::vector<A> & = {} ); There is an incomplete class A, and ...
Fedor's user avatar
  • 24.8k
0 votes
0 answers
160 views

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) { ...
River's user avatar
  • 1
1 vote
1 answer
511 views

eI have a template class, similar to the following class. The behaviour is not that relevant, important is, that it has an array as attribute which stores T and its size depends on the template ...
Sandro Koch's user avatar
4 votes
0 answers
203 views

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(); ...
zwhconst's user avatar
  • 1,657
0 votes
1 answer
921 views

The files are organized as following: //MyClass.h #pragma once namespace std { class ostream; }; class MyClass { private: int a; public: friend std::ostream& operator<<(std::...
SZYoo's user avatar
  • 508
-2 votes
2 answers
142 views

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/...
Tom Huntington's user avatar
0 votes
1 answer
97 views

The following code works, but it is not very readable to have methods separated from each state of this state machine: struct Base { virtual Base* next() = 0; }; struct StateA : public Base { ...
nowox's user avatar
  • 29.7k
3 votes
3 answers
544 views

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 ...
glades's user avatar
  • 5,392
1 vote
1 answer
79 views

So I have two classes inherites from a base class, and I want each of them to have members that call the constructor for the other. Something like; class BaseClass { protected: BaseClass* a; ...
Jordan Powers's user avatar
3 votes
1 answer
112 views

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->...
codeling's user avatar
  • 11.5k
1 vote
1 answer
43 views

Tried to create a forward declaration for boost::gil::rgba8_image_t: namespace boost::gil { class rgba8_image_t; } And got this: ... error: definition of type 'rgba8_image_t' conflicts with type ...
Serg Kryvonos's user avatar
1 vote
1 answer
170 views

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 ...
Nirvana's user avatar
  • 663
0 votes
3 answers
256 views

I've been told we somehow need them so the compiler can continue onwards without having read the definition yet. Somehow we need them in order for the program to work properly, to avoid conflicts ...
Bluesman's user avatar
-1 votes
3 answers
424 views

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 ...
the-baby-is-you's user avatar
1 vote
1 answer
262 views

The following example compiles BUT gcc warns me that the friend declaration is in fact not a templated function. I don't understand what exactly I'm supposed to change. Clang and MSVC accept this code ...
glades's user avatar
  • 5,392
0 votes
1 answer
86 views

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 ...
Anuhas's user avatar
  • 9
0 votes
1 answer
75 views

Consider the following code: class I_Clipboard { public: virtual ~I_Clipboard () = default; virtual Type_A copied_ta() const = 0; virtual void set_copied_ta(const Type_A & ta) = 0; ...
comp1201's user avatar
  • 425
2 votes
1 answer
195 views

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); // ...
MisterOfficer_234's user avatar
0 votes
3 answers
226 views

Have looked at various similar questions here but still can't figure out why the following code does not compile: // these three are defined somewhere class A; std::unique_ptr<A> make_a(); void ...
frumle's user avatar
  • 623
1 vote
1 answer
310 views

Consider the following scenario: "A.cpp": void fun() { std::cout << "fun() global\n"; } "B.cpp": namespace N { void f() { std::cout << "...
CinCout's user avatar
  • 9,639
2 votes
2 answers
2k views

I have encountered a reference problem like this Example 1; @dataclass class Book: book_id:int book_name:str book_library: Library #The object where book is stored @dataclass class Library:...
edwar.green's user avatar
3 votes
1 answer
262 views

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&...
Antonio Di Bacco's user avatar
0 votes
1 answer
111 views

In my public header, I am trying to add a pointer to an object which is only defined privately. Normally that would be simple. I just forward-declare. However, the object is a bit complicated and I'...
Stewart's user avatar
  • 5,230
2 votes
1 answer
201 views

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 ...
bitmask's user avatar
  • 35.2k
0 votes
1 answer
86 views

I am forced to use the architecture which will be presented below. Forward declaration is the pattern I'm trying to implement to counter the issue. Here is what I have so far : class_with_config.h : #...
LPo's user avatar
  • 95
0 votes
0 answers
1k views

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: ...
Legoshark's user avatar
1 vote
1 answer
130 views

I'm sure that this has been asked, but I cannot find the question or answer, so here is the minimal code I tried to compile. // goof4.cpp : This file contains the 'main' function. Program execution ...
davidbear's user avatar
  • 415
0 votes
1 answer
148 views

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: ...
Gulzar's user avatar
  • 28.8k
0 votes
0 answers
33 views

I am trying to use a visitor 'BehaviorVisitor' which has a method for each type of 'Flower' such as 'Sunflower'. I keep getting this error from BehaviorVisitor: error: variable has incomplete type '...
callum arul's user avatar
1 vote
1 answer
618 views

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 ...
warrior_monk's user avatar
2 votes
0 answers
182 views

I'm looking for a way to remove some header file dependencies. I'm working on a test project which runs a Windows UI in C# on a backend written in LabVIEW compiled to a DLL. Right now, I compile the ...
MoogsDoog's user avatar
2 votes
2 answers
139 views

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: #...
einpoklum's user avatar
  • 138k
0 votes
2 answers
951 views

I am writing a pretty huge program with lots of templated functions. Naturally, the program has a long compile-time, which is why I wanted to use forward declaration. Now there are a lot of functions ...
wittn's user avatar
  • 320

1
2 3 4 5
22