Yeah if I'm working with C++ it's C++11.
@Fred: Visual Studio is falling behind on its C++11 support, which sucks since for a Windows IDE I think it's unparalleled.
VS2010 supports very little c++11, VS2012 supports much more although it is not complete yet. People should remember that unlike clang and gcc the VS team focus on stability rather then rushing to include new features. I would love if VS was fully c++11 compliant, but I'm willing to wait.
class myclass{
public:
//public constructors
myclass(); //no args
myclass(constint&); //set it equal to an int...
~myclass();
//rest here
private:
int mystoredint; //constructors will assign a value to this accordingly
};
//in the cpp file:
myclass::myclass(constint& i)
{
myclass::mystoredint = i;
}
myclass::myclass()
{
myclass::mystoredint = 0;
}
myclass::~myclass()
{
}
//in a function:
myclass duh = 5;
//now the class = 5.
myclass duh; //the no-arg constructor is called, setting the class to 0, it's default.
I don't usually mess with setting defaults. I just pass by address with constants, and overload if I really need a place where I don't want to pass a variable. This way, I know that the compiler will catch my errors in the passing or arguments. I had a LOT less syntactical issues since I started doing that.
In short, I am not familiar with in-class initialization of defaults.
You don't need to tell me that Andy. I know c++ syntax(with the exception of some c++11 and standard library functions) like the back of my hand because I just read a book on it.
I also don't see why you should use constructor initializer lists. IIRC all they do is make sure those objects are constructed before the object that is being constructed. I'm pretty sure this doesn't make a difference when using primitive types like integers.
That is like saying instead of doing this: int i = 55;
you should do this:
1 2
int i;
i=55;
Actually that is nothing like doing that. When you use a constructor initializer list you are directly initializing a value to the member not assigning a value.
That is why you can assign a value to a const member when you use constructor initializer list.