Skip to main content
Filter by
Sorted by
Tagged with
4 votes
3 answers
191 views

The following class compiles just fine: class Time { public: Time(int h = 0, int m = 0, int s = 0); // constructor with default parameters Time(); // default ...
josch's user avatar
  • 7,309
1 vote
3 answers
115 views

I have a class with a default constructor which initializes many member variables via initializer lists. I wish to have a parametrized constructor which only updates one of the member variables. A ...
Engineer999's user avatar
  • 4,159
2 votes
1 answer
136 views

struct PhiBlock { int64_t bsize; // block size vector<int64_t> ind; // 0/1 to track [pmin(y) > pb] fenwick_tree phi_sum; // partial sums PhiBlock ...
qwr's user avatar
  • 11.6k
0 votes
1 answer
96 views

While refactoring some code, I've run into an issue with heap corruption. namespace GPU { struct ShaderStage { public: ShaderStage(ShaderStageType, const Path&); ...
garlfin's user avatar
  • 11
6 votes
1 answer
318 views

Consider the following example that compiles with clang but is rejected by edg, gcc and msvc. Demo #include <initializer_list> struct C { C(){} C(std::initializer_list<int> i = {...
Richard's user avatar
  • 47k
3 votes
1 answer
173 views

struct X { X() = default; X(const X& src) { cout << "copy" << endl; } }; int main() { X x1; X x2(move(x1)); } Output: copy struct ...
Andrey Rubliov's user avatar
1 vote
1 answer
121 views

std::string str; std::string(str); std::string str = {}; Are they the same? If no then what's the difference? And when should I use each of them? New to C++ and trying to understand the different ...
Heca's user avatar
  • 39
2 votes
0 answers
113 views

The following code snippet #include <iostream> #include <vector> class IntegerContainer { public: IntegerContainer() { std::cout << "default" << std::...
Jan Hackenberg's user avatar
2 votes
3 answers
457 views

In Spring boot if we are creating a POJO class and we end up creating only a parameterized constructor and not any default constructor then Java will throw errors, why does this happen if Java ...
Ananthu K Kumar's user avatar
1 vote
2 answers
154 views

I have a class String and I've made a field char* name, default, parameterized, copy constructor, destructor and overwritten operator =. My question is how my default constructor should look like for ...
zaraboy's user avatar
  • 21
1 vote
3 answers
195 views

Consider the following code: #include <type_traits> template<typename T> struct A1 { T t; // implicitly-declared default constructor }; template<typename T> struct A2 { ...
xmllmx's user avatar
  • 44.6k
0 votes
1 answer
64 views

I created a class Event class Event { char m_event_desc[DESC_LENGTH + 1]; // description of the event unsigned int m_time; // time when the event starts unsigned int getHour(); ...
Himawari.Ksm's user avatar
-1 votes
1 answer
107 views

c++ primer says : The default constructor is used automatically whenever an object is default or value initialized. Default initialization happens • When we define nonstatic variables (§ 2.2.1, p. 43)...
semicolon_missing's user avatar
0 votes
1 answer
82 views

I need to implement an AutoDocs class that will contain information about the license plate number and driver's full name. It is necessary to implement the class with the following invariants: the ...
swecpp's user avatar
  • 13
-1 votes
2 answers
183 views

Could an implicit compiler created default constructor have more than a null body? According to IBM's website, the answer is: no. I have this project that's kind of stumping me though: This is where ...
Horace's user avatar
  • 163
0 votes
0 answers
37 views

I've defined a C# struct: public struct Separator { readonly StringBuilder sb; readonly char ch; bool more; public void Write() { if (more) sb.Append(ch); ...
rwallace's user avatar
  • 34.1k
0 votes
2 answers
69 views

I have a below lambda default Employee constructor which is working fine. this.For<IEmployee>().Use(() => new Employee()); Now I want to call another another constructer based on flag value. ...
Shakeer Hussain's user avatar
3 votes
1 answer
2k views

I've got a code really similar to the snippet below: #include <vector> struct dummy { std::vector<int> const data; dummy() = default; }; Most compilers accept this code without a ...
Oersted's user avatar
  • 3,834
17 votes
1 answer
699 views

I don't understand why in foobar below I need to specify std::vector<int>{} whereas in foobar2 I do not: #include <iostream> #include <memory> #include <vector> #include <...
jwezorek's user avatar
  • 10k
3 votes
0 answers
402 views

I've got a class that basically contains a std::vector. I can default-construct an object of this class, leaving the contained std::vector empty. I can also value-construct it from a set of values, ...
Oersted's user avatar
  • 3,834
0 votes
2 answers
122 views

Is there a way to initialize an array of objects which don't have a default constructor? struct IndexAndSign { const int depth; const bool baseIsPositive; IndexAndSign(int depth, bool ...
Reska's user avatar
  • 17
1 vote
1 answer
121 views

I want to implement my own heap allocation function to do the same as the C++ new operator when it comes to allocating elements of a class type. My allocation function (for Windows) does not use the ...
user avatar
-2 votes
1 answer
81 views

I made a class with a default constructor and a subclass. When I try to create an instance of the subclass using a default constructor, I get the errors C2512 (no appropriate default constructor ...
FoxVocs's user avatar
  • 41
0 votes
1 answer
76 views

I have a struct: struct holder { int val; std::unordered_map<int, int> num_to_addr; }; I dynamically allocate a struct holder: struct holder* handle = new struct holder; I do work and ...
Troy Hamilton's user avatar
1 vote
1 answer
95 views

I am writing a student project. For some reason all variables of this object are set to 0 or false, despite the fact that the constructor have default arguments set. The class of this object inherit ...
Szymon Nowaczyk - Słomian's user avatar
1 vote
1 answer
151 views

#include <iostream> #include <memory> using namespace std; class Init { private: int x; public: Init(int y) { x = y; cout << "default constructor ...
chandu's user avatar
  • 85
0 votes
1 answer
496 views

Sorry in advance for what may be a bad post. I've scoured stackoverflow for pre existing posts that answer my question, but although many posts on here are similar, none of them seem to apply to my ...
JohnZ's user avatar
  • 143
-3 votes
1 answer
1k views

I have been trying to make a struct with general information I want to use throughout my program. I'm updating this information in my Mario::init() function, but now its giving me this error: No ...
ggjorven's user avatar
1 vote
0 answers
66 views

See this godbolt: struct Foo { Foo() noexcept = default; int t{}; }; struct Bar { Foo baz{}; }; int main() { return Bar { .baz = Foo{} }.baz.t; } When deleting ...
JanKXSKI's user avatar
-2 votes
1 answer
177 views

class MyClass : public ParentClass { public: explicit MyClass(classA a, const classB b) : A(a), B{b} {} MyClass() override = default; MyClass(const MyClass&) = delete; ...
Naresh's user avatar
  • 11
0 votes
0 answers
178 views

Is there any difference where (e.g. in a header or in a source file) to declare a default constructor? I mean, is there any difference in time execution performance in these cases? That is, should // ...
elo's user avatar
  • 561
0 votes
1 answer
1k views

I want mapstruct to not use a no-args-constructor even though it exists in my DTOs and Entities (as far as I know jsonb, jpa, jaxb, ... usually require a no-args-constructor): @RequiredArgsConstructor ...
r-uu's user avatar
  • 647
2 votes
1 answer
121 views

Here's what I have: Demo #include <cstdio> #include <memory_resource> #include <memory> #include <string_view> #include <array> #include <utility> /* declval */ ...
glades's user avatar
  • 5,374
1 vote
1 answer
109 views

While exploring the ArrayList class, I can't figure out the following part (constructor of the inner class Itr): // prevent creating a synthetic constructor Itr() {} I kinda understand what the "...
ioan.dm's user avatar
  • 13
-1 votes
2 answers
183 views

I'm currently making c++ project but this error is bothering me for long time and i cannot figure out why this doesn't work. I was searching about this error but still i don't understand it. Thanks in ...
dawidosin's user avatar
3 votes
2 answers
130 views

class AAA { int m_Int; public: AAA() : m_Int{12} {} }; class BBB { int m_Int1; public: BBB() : m_Int1{12} {} }; class CCC : public AAA, public BBB {}; AAA a; BBB b; CCC c{ a, b }; ...
Sheperd's user avatar
  • 41
1 vote
1 answer
386 views

Considering this MRE (the real case involves some class with some inheritance and some member variables) class A { public: A() = default; explicit A(const A&) = default; // ...
Antonio's user avatar
  • 20.6k
1 vote
1 answer
1k views

I have a very large struct that has customized copying constructor, customized moving constructor, customized moving assignator, and customized copying assignator, but I also need to use Designated ...
Leon's user avatar
  • 2,165
0 votes
1 answer
67 views

**the first constructor is supposed to take words from a txt file and the second one takes words from the string and add it to fileVec vector. i'm trying to call a parameterized constructor but it ...
Omar Ayman's user avatar
1 vote
2 answers
118 views

It seems that in virtual inheritance, operator= and copy constructor are treated differently. Consider the following code: #include <iostream> #include <ostream> class A { public: A(...
Hans's user avatar
  • 37
0 votes
1 answer
117 views

Given the non trivial data structure: claas MyClass { public: MyClass():x(0), p(nullptr) {} private: int x; int* p; }; Is there any guarantee provided by the c++ specification that the ...
Sampath's user avatar
  • 1,202
1 vote
1 answer
202 views

Very recently, I have started learning C++ full-time. It is my understanding that constructors in C++ are not inherited by subclasses, and therefore must be declared in the subclass. Below, I have a ...
Jarad's user avatar
  • 11
0 votes
3 answers
555 views

I just a have a problem in understanding when the compiler marks the constructor as constexpr. If I write the following program: struct S{ S() {}; } constexpr S s{ }; Does this mean that the default ...
mada's user avatar
  • 2,033
0 votes
0 answers
22 views

I am making an object class inherited from my base class. I am trying to make my default non argument constructor using this(), and it keeps highlighting red when I try to make a default Date object ...
Daniel Rojas's user avatar
1 vote
2 answers
1k views

What are the ramifications of assigning a class variable when defining the class versus in the class constructor? Is the variable assigned in the class definition accessible by all class instances? ...
Carter Canedy's user avatar
1 vote
0 answers
115 views

This problem is related to Kotlin noarg plugin not initializing default values. I've got my NoArg plugin set up like this: plugins { id "org.jetbrains.kotlin.plugin.noarg" version "...
Cactusroot's user avatar
  • 1,058
1 vote
2 answers
545 views

I have seen a lot of times people adding the default constructor of base class in the derived class constructor initializer list like so DerivedClass::DerivedClass(int x) : BaseClass(), member_derived(...
ontherocks's user avatar
  • 2,093
-1 votes
1 answer
48 views

I am doing a little .NET application to get use to it but I struggle to understand something. When I pass through the following line of code the parameterless constructor of my Historique class is ...
Floriant Fekete's user avatar
1 vote
1 answer
535 views

Per cppreference, the syntax for value initialization is: [..] T object {}; (since C++11) [..] It's already known that value-initialization is performed when an object is constructed with an empty ...
mada's user avatar
  • 2,033
1 vote
2 answers
492 views

I came across this example from cppreference: ... struct T3 { int mem1; std::string mem2; T3() {} // user-provided default constructor } ... This example clearly show that the given ...
mada's user avatar
  • 2,033

1
2 3 4 5
17