Syfu_H

1

votes
1

answer
43

views

Can an inline or constexpr function be defined multiple times in a program? [duplicate]

This question already has an answer here: What means “obey ODR” in case of inline and constexpr function? 3 answers I am reading C++ Primer book. I find it really interesting and easy to understand for a beginner like me. But when I reached this topic: 'Put inline and constexpr Functions in He...
Syfu_H
16

votes
4

answer
887

views

Why can I not instantiate a class whose constructor is private in a friend class?

I have two classes; Salary that is intended to hold information and calculations regarding the salary of an employee and Employee that has an object of type class Salary and some members like name and address of the employee... What I want to do is to prevent class Salary from being instantiated exc...
Syfu_H
7

votes
4

answer
193

views

Why I cannot instantiate a class whose constructor is private in a friend class?

I have two classes; Salary that is intended to hold information and calculations regarding the salary of an employee and Employee that has an object of type class Salary and some members like name and address of the employee... What I want to do is to prevent class Salary from being instantiated and...
Syfu_H
1

votes
4

answer
61

views

How can I print a vector in a recursive function?

I have a problem here: I am to write a function that prints the elements of a vector recursively so no loop is allowed. I tried this code but it crashes at runtime: void print(const std::vector ivec, std::vector::const_iterator it) { if (it == ivec.end()) return; std::cout
Syfu_H
6

votes
2

answer
108

views

What is the point in using typedef to declare a functon?

I am a bit confused about why I can use typedef to declare functions. Here is my example: int Add(int a, int b) { return a + b; } int Mult(int a, int b) { return a * b; } typedef int func(int, int); int main(int argc, char* argv[]){ func Add; cout
Syfu_H
19

votes
3

answer
1.3k

views

How to call a function with default parameter through a pointer to function that is the return of another function?

I have a function Mult that takes two integers and returns the product of its parameters. And a function Double that takes an integer and returns a pointer to function that returns an integer and takes two integer parameters like Mult. Mult's second parameter is default So when I call Double, Double...
Syfu_H
8

votes
3

answer
483

views

What is the result of assigning to std::vector<T>::begin()?

I've a bit understanding about lvalue and rvalues. So as I know we cannot assign to an rvalue but non-const lvalue is ok. #include #include int main(){ std::vector v{ 1, 2, 3, 4, 5 }; v.begin() = v.end() - 2; std::cout
Syfu_H