Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

Question Inherit the functions of a metaprogrammed class

Hi, while trying to hone my skills by creating a meta-programmed class construct along with the concepts of inheritance I came across this oddity (it's a simplified version of what I'm trying to do):

C++:
#include <iostream>

template<class T>
class BASE
{
public:
void func()
{
std::cout << "Hello world";
}

};

template<class T>
class DERIVED : public BASE<T>
{
public:

void func2()
{
func(); // <-- 'func': identificatore non trovato
}
};

int main()
{
DERIVED<int> obj;
obj.func2();
}

As you can guess from the comment, the func (); included in the scope of func2 (); is not recognized, while in the case of a non meta-programmed class the code would be compiled without errors:

C++:
#include <iostream>

class BASE
{
public:
void func()
{
std::cout << "Hello world";
}

};

class DERIVED : public BASE
{
public:

void func2()
{
func();
}
};

int main()
{
DERIVED obj;
obj.func2();
}

I've also tried making func2 (); a virtualization of func () ;, but the function call func (); gives rise to a buffer overflow.

C++:
#include <iostream>

template<class T>
class BASE
{
public:
virtual void func()
{
std::cout << "Hello world";
}

};

template<class T>
class DERIVED : public BASE<T>
{
public:

void func() override
{ // Buffer overflow
func();
}
};

int main()
{
DERIVED<int> obj;
obj.func();
}

So I wonder, how is it possible to do such a thing: ???:?
Would love to see this question answer 😀 I started learning class and struct yesterday

Thanks have a good day all !


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by lockheadApr 22, 2021 07:10 AM 0 147 Apr 22, 2021 07:10 AM
Last Post: lockhead
[Python] by Meelo XOMay 11, 2019 05:52 AM 0 120 May 11, 2019 05:52 AM
Last Post: Meelo XO
[C] by zapotecsNov 4, 2015 03:55 PM 1 155 Nov 4, 2015 03:55 PM
Last Post: ValiumProp