Программы на C++. Форум разработчиков
Anonymous
Нет ./a.out, созданный в g++
Сообщение
Anonymous » 10 окт 2024, 00:41
У меня есть следующая программа:
Код: Выделить всё
#include "Sptr.cpp"
#include
#include
#include
namespace my {
template
class Sptr {
private:
//some kind of pointer
//one to current obj
T obj;
size_t reference_count;
//one to original obj
public:
Sptr();
template
Sptr(U *);
Sptr(const Sptr &);
template
Sptr(const Sptr &);
template
Sptr &operator=(const Sptr &);
void reset();
T* operator->() const
{return &obj;};
T& operator*() const
{return obj;};
T* get() const
{return &obj;};
//operator unspecified_bool_type() const;
//overload *,->,=,copy-constructor
// const-ness should be preserved.
// Test for null using safe-bool idiom
// Static casting, returns a smart pointer
};
template
Sptr::Sptr() {
//do something
}
template
template
Sptr::Sptr(U* u) {
//do something
}
template
Sptr::Sptr(const Sptr ©Obj) {
//do copy constructor stuff
}
template
template
Sptr& Sptr::operator=(const Sptr &t) {
return *this;
}
template
void Sptr::reset() {
//do something
}
template
bool operator==(const Sptr &, const Sptr &) {
//do something
return true;
}
template
Sptr static_pointer_cast(const Sptr &sp) {
//do something
return true;
}
template
Sptr dynamic_pointer_cast(const Sptr &sp) {
//Do something
return true;
}
}
using namespace std;
using namespace my;
/* Basic Tests 1 ================================================================================ */
class Base1 {
protected:
Base1() : derived_destructor_called(false) {
printf("Base1::Base1()\n");
}
private:
Base1(const Base1 &); // Disallow.
Base1 &operator=(const Base1 &); // Disallow.
protected:
~Base1() {
printf("Base1::~Base1()\n");
assert(derived_destructor_called);
}
protected:
bool derived_destructor_called;
};
class Derived : public Base1 {
friend void basic_tests_1();
private:
Derived() {}
Derived(const Derived &); // Disallow.
Derived &operator=(const Derived &); // Disallow.
public:
~Derived() {
printf("Derived::~Derived()\n");
derived_destructor_called = true;
}
int value;
};
void basic_tests_1() {
}
int main(int argc, char *argv[]) {
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/15713102/no-a-out-produced-in-g[/url]
1728510077
Anonymous
У меня есть следующая программа: [code]#include "Sptr.cpp" #include #include #include namespace my { template class Sptr { private: //some kind of pointer //one to current obj T obj; size_t reference_count; //one to original obj public: Sptr(); template Sptr(U *); Sptr(const Sptr &); template Sptr(const Sptr &); template Sptr &operator=(const Sptr &); void reset(); T* operator->() const {return &obj;}; T& operator*() const {return obj;}; T* get() const {return &obj;}; //operator unspecified_bool_type() const; //overload *,->,=,copy-constructor // const-ness should be preserved. // Test for null using safe-bool idiom // Static casting, returns a smart pointer }; template Sptr::Sptr() { //do something } template template Sptr::Sptr(U* u) { //do something } template Sptr::Sptr(const Sptr ©Obj) { //do copy constructor stuff } template template Sptr& Sptr::operator=(const Sptr &t) { return *this; } template void Sptr::reset() { //do something } template bool operator==(const Sptr &, const Sptr &) { //do something return true; } template Sptr static_pointer_cast(const Sptr &sp) { //do something return true; } template Sptr dynamic_pointer_cast(const Sptr &sp) { //Do something return true; } } using namespace std; using namespace my; /* Basic Tests 1 ================================================================================ */ class Base1 { protected: Base1() : derived_destructor_called(false) { printf("Base1::Base1()\n"); } private: Base1(const Base1 &); // Disallow. Base1 &operator=(const Base1 &); // Disallow. protected: ~Base1() { printf("Base1::~Base1()\n"); assert(derived_destructor_called); } protected: bool derived_destructor_called; }; class Derived : public Base1 { friend void basic_tests_1(); private: Derived() {} Derived(const Derived &); // Disallow. Derived &operator=(const Derived &); // Disallow. public: ~Derived() { printf("Derived::~Derived()\n"); derived_destructor_called = true; } int value; }; void basic_tests_1() { } int main(int argc, char *argv[]) { cout Подробнее здесь: [url]https://stackoverflow.com/questions/15713102/no-a-out-produced-in-g[/url]