Skip to main content

All Questions

Tagged with
0 votes
0 answers
23 views

Cereal archive called from DLL cause polymorphism not to work

I am a newbie to cereal and lately I ran into an odd issue, I have my serialization code inside an external DLL, in the code I use cereal's polymorphism functionality, when trying to invoke the ...
stav12212's user avatar
0 votes
0 answers
38 views

create object type based on base type member function return value

I am implementing a loadbalancer that should choose balancing strategy based on some logic: class LoadBalancer{ public: bool get_backend_cpu_info(){// some complicate logic involve member ...
Yufei Zheng's user avatar
-1 votes
0 answers
56 views

Compiler misidentifying/unrecognising type [duplicate]

I have the following class with constructor: command.h: #include "./robots.h" enum class CMD { //...... }; class CommandTemplate { //..... public: virtual std::unique_ptr<...
steve89's user avatar
16 votes
1 answer
1k views

How does C++ select the `delete` operator in case of replacement in subclass?

Let's assume I have the following code (https://godbolt.org/z/MW4ETf7a8): X.h #include <iostream> struct X{ void* operator new(std::size_t size) { std::cout << "new X\...
Shady Atef's user avatar
  • 2,339
2 votes
3 answers
154 views

In C++, compared to final or not virtual function, what is the advantage of CRTP?

I'm new to learning modern C++ programming. I have read many blogs and questions but haven't found the answer of this question. In C++, compared to final or not virtual function, what is the advantage ...
CatFood's user avatar
  • 33
0 votes
1 answer
74 views

Strange inheritance behavior with base class

I hope someone can help me since can't quite understand how it is possible that the following code can work. I have a base class with some classes that derive from it. Each derived class has its own ...
lightimpact90's user avatar
0 votes
1 answer
52 views

Accessing Private Members of Derived Class through Base Class Pointer with Virtual Function in C++

I have a scenario in C++ where I'm accessing private members of a derived class through a base class pointer, and it seems to work without any errors. Here's a simplified version of the code: #include ...
Hamza's user avatar
  • 42
0 votes
0 answers
16 views

Derived class as argument of OpenCL kernel function

I am trying to compile the following OpenCL kernel code with clang-16: clang-16 -cl-std=clc++2021 -c -emit-llvm -target spir64 -Xclang -finclude-default-header \ -o /workspace/test/...
Jackdu0049's user avatar
1 vote
1 answer
44 views

Polymorphic return type for child classes

I want to make an abstract class with a pure virtual function process. process should return a variable of type Result: class Base { public: class Result { public: int a = 1; ...
Ivan's user avatar
  • 1,423
1 vote
2 answers
71 views

C++ multiple inheritance- class method running twice

I have an exercise to practice multiple inheritance and polymorphism and something is not going well. The exercise includes 4 classes I need to build: Creature char * name int age int ...
Reef Kenig's user avatar
-1 votes
2 answers
63 views

Polymorphic behavior of derived class objects in C++ STL list [duplicate]

I am storing objects of base and derives classes (Account, StudentAccount, EmployeeAccount) in an STL list and process them with STL Iterator. The dynamic polymorphic behavior of objects is not ...
Syed Irfan Ahmad's user avatar
0 votes
0 answers
27 views

Unexpected vTable look-up for non-virtual method in C++ [duplicate]

The code snippet below explains the problem: class base_obj_with_virtual_func { public: int variable_int; virtual void print_name() { std::cout << "Base obj " << this <...
cvbrgava's user avatar
0 votes
1 answer
39 views

Why is dynamic dispatch not working within a template function?

I have the following code. There is a base class (Node) and a derived class (NumberExprNode) that each have a virtual equality method. #include <vector> #include <memory> #include <...
Dean DeRosa's user avatar
0 votes
1 answer
47 views

How to call derived type methods from vector of base type stored in a different class?

say I have some class foo that has a vector of pointers to another class Bar and a LogBarVec() method that logs each Bar's internal type: class Foo { std::vector<std::unique_ptr<Bar>> ...
gerfg grgr's user avatar
0 votes
1 answer
75 views

When is it appropriate to assign a unique_ptr to a shared_ptr?

This is a follow up to the question that was asked here: Does C++11 unique_ptr and shared_ptr able to convert to each other's type? and more specifically the top voted answer. The snippet that caught ...
Sailanarmo's user avatar
  • 1,181

15 30 50 per page
1
2 3 4 5
244