Re: possibility to forbid use of "this"?

From: Ernst Murnleitner (mur-spam_at_awite.de)
Date: 01/07/04


Date: Wed, 7 Jan 2004 16:46:03 +0100


> That shouldn't compile - the constructor of shared_ptr taking a T* is
> explicit, so a pointer can't implicitly convert to a shared_ptr.
>

With gcc 2.95 it compiles:

// -------------------------------------
#include <iostream.h>

#include <stdlib.h>

#include <boost/shared_ptr.hpp>

class A;

typedef boost::shared_ptr<A> APtr;

class A {

public:

A(){};

virtual ~A(){};

virtual void f(){func(this); };

void func(APtr p) {cout << "func(APtr)" << std::endl;};

};

int main(int argc, char *argv[])

{

A a;

a.f();

return EXIT_SUCCESS;

}

// -------------------------------------



Relevant Pages

  • Re: problem with rand()
    ... > Using gcc, this compiles, runs, and outputs as expected, but on ... > using namespace std; ... > int main ...
    (comp.lang.cpp)
  • Re: nextPow2 in x86
    ... int nextPow2 ... ...which compiles with gcc to... ... Is it possible to do this operation faster somehow with handwritten ...
    (comp.lang.asm.x86)
  • pushing the limits of use-before-declaration within a class
    ... int main ... The version of GCC I am using compiles and links it, ... is not only a member class but whose instance must ...
    (comp.lang.cpp)
  • Problem with implicit conversion
    ... I have written a program that compiles just fine with GCC 3.3. ... ../Testp.c: In function `int main': ... template class BasisF; ...
    (comp.lang.cpp)
  • Re: data types
    ... Usually short is smaller than an int. ... Your compiler is either *really* old or broken or both. ... recommend either a version of gcc,, or Visual Studio ... Microsoft's Visual Studio Express has an onerous EULA). ...
    (comp.lang.c)