GO, c's younger copycat brother?

Pages: 12
Thank You.
I believe auto_ptr is the predecesor to shared_ptr and unique_ptr.
Heres an example from http://www.cplusplus.com/reference/memory/auto_ptr/auto_ptr/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// auto_ptr example
#include <iostream>
#include <memory>

int main () {
  std::auto_ptr<int> p1 (new int);
  *p1.get()=10;

  std::auto_ptr<int> p2 (p1);

  std::cout << "p2 points to " << *p2 << '\n';
  // (p1 is now null-pointer auto_ptr)

  return 0;
}


http://www.cplusplus.com/reference/memory/auto_ptr/
http://www.cplusplus.com/reference/memory/shared_ptr/
http://www.cplusplus.com/reference/memory/unique_ptr/
"Auto pointer" means "automatic pointer" (also known as a "smart pointer"). It's a pointer to a dynamically-allocated resource that automatically calls delete on the pointed resource when it goes out of scope so that you don't have to do it manually. C++11 provides two classes: auto_ptr and shared_ptr. The difference is that two shared_ptr objects can point to the same resource, whereas if you assign the same resource to two auto_ptr objects, the first one gets set to NULL:

1
2
3
4
5
std::auto_ptr<int> p1(new int);
std::cout << p1.get(); // Prints address
std::auto_ptr<int> p2 = p1;
std::cout << p1.get(); // Prints NULL
std::cout << p2.get(); // Prints address 


Also auto is evaluated at compile-time, not at runtime.

[edit] Guess I lost the race :P
Last edited on
@chrisname
shared_ptr and unique_ptr were introduced in c++11, but auto_ptr was already part of the standard (I dont know when it was included)
Oops, my mistake.
closed account (Dy7SLyTq)
sorry i meant compile time. ive been doing a lot of python so i got used to run-time. so reading through this, i decided not to continue learning go. what are redundancies, and what does python have to offer that c++ doesn't?
what does python have to offer that c++ doesn't?

Theoretical they are both Turing Complete. However python is much better suited to rapid development, while C++ is more suited where you need speed or low lever control.
closed account (Dy7SLyTq)
sorry i meant haskell.
Lots of things, it's a totally different language. Read this if you want to know more: http://www.haskell.org/haskellwiki/Introduction#Why_use_Haskell.3F
Topic archived. No new replies allowed.
Pages: 12