Message from C, C++ talks

July 2019

— #noendl

— Have a look at these :

Message permanent page

— Guys
If I have:

struct base{
virtual ~base(){}

struct derive : base{};

And I have the following function:

template<typename T>
void foo(T* t){/*some code*/}

In main:
I called foo first with an instance of base*

foo(new base);

Now, one of the foo instances is:
void foo(base* t)
Call this instance A.

Again I called foo again with instance of derive*:

foo(new derive);

Now, the question is:
Does the second call of foo refers to a new instance of foo function like:
void foo(derive* t){/***/}

or it just refers to the first instance A and we have a runtime polymorphism?!!

Message permanent page

— It's a different instance, they're generated at compile time


New instance. The templates are expanded at compile time and you'd end up with the two foo's you listed

— Welcome

— Got it

— Thanks

— It may be even more if you mix (non)const vars

— Guys i was solving this problem of largest contiguous sub array sum. And my friend asked this question, you have to select an integer X from the array A then square it and then return the sum of the subarray that has maximum sum over all subarrays of the resultant array. Sum of subarrays is the sum of all integers in subarray. How to tackle this problem

Message permanent page



— I need help

— It seems like your name notes that you are the “Pro” so what can be your problem?

— Lol.