Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 2 years ago.
Here is the a.h header:
#include <string>
template <typename L>
class A
{
L l;
public:
A() : l("a-text") {}
const std::string get() const { l.get(); } // <<<< Edit: missing return!
};
And here is a.cpp:
#include "a.h"
#include <iostream>
class L {
const std::string v;
public:
L(const std::string& v_): v(v_) {}
const std::string get() const { return v; }
};
int main() {
L l("l-text");
std::cout << l.get().c_str() << std::endl;
A<L> a;
std::cout << a.get().c_str() << std::endl; // <<<< - this will report Segmentation fault
return 0;
}
The first std::cout
will work okay displaying l-text
Yet the second std::cout
will report Segmentation fault instead of displaying a-text.
Thanks in advance!