C++版本是-std=c++11
#include <iostream>
class Codinghuang
{
public:
Codinghuang()
{
std::cout << "1" << std::endl;
}
Codinghuang(Codinghuang &coding)
{
std::cout << "2" << std::endl;
}
Codinghuang(const Codinghuang &coding)
{
std::cout << "3" << std::endl;
}
};
int main()
{
Codinghuang();
}
[root@aaeb2c267d0f test]# g++ -std=c++11 test.cpp
[root@aaeb2c267d0f test]# ./a.out
1
[root@aaeb2c267d0f test]#
#include <iostream>
class Codinghuang
{
public:
Codinghuang()
{
std::cout << "1" << std::endl;
}
Codinghuang(Codinghuang &coding)
{
std::cout << "2" << std::endl;
}
Codinghuang(const Codinghuang &coding)
{
std::cout << "3" << std::endl;
}
};
int main()
{
Codinghuang c1 = Codinghuang();
}
[root@aaeb2c267d0f test]# g++ -std=c++11 test.cpp
[root@aaeb2c267d0f test]# ./a.out
1
[root@aaeb2c267d0f test]#
[root@aaeb2c267d0f test]# g++ -std=c++11 -fno-elide-constructors test.cpp
[root@aaeb2c267d0f test]# ./a.out
1
3
[root@aaeb2c267d0f test]#
#include <iostream>
class Codinghuang
{
public:
Codinghuang()
{
std::cout << "1" << std::endl;
}
Codinghuang(Codinghuang &coding)
{
std::cout << "2" << std::endl;
}
Codinghuang(const Codinghuang &coding)
{
std::cout << "3" << std::endl;
}
Codinghuang(Codinghuang &&coding)
{
std::cout << "4" << std::endl;
}
};
int main()
{
Codinghuang c1 = Codinghuang();
}
[root@aaeb2c267d0f test]# g++ -std=c++11 test.cpp
[root@aaeb2c267d0f test]# ./a.out
1
[root@aaeb2c267d0f test]#
[root@aaeb2c267d0f test]# g++ -std=c++11 -fno-elide-constructors test.cpp
[root@aaeb2c267d0f test]# ./a.out
1
4
[root@aaeb2c267d0f test]#
#include <iostream>
class Codinghuang
{
public:
Codinghuang()
{
std::cout << "1" << std::endl;
}
Codinghuang(Codinghuang &coding)
{
std::cout << "2" << std::endl;
}
Codinghuang(const Codinghuang &coding)
{
std::cout << "3" << std::endl;
}
Codinghuang(Codinghuang &&coding)
{
std::cout << "4" << std::endl;
}
};
int main()
{
Codinghuang c1;
Codinghuang c2 = c1;
}
[root@aaeb2c267d0f test]# g++ -std=c++11 test.cpp
[root@aaeb2c267d0f test]# ./a.out
1
2
[root@aaeb2c267d0f test]#
#include <iostream>
class Codinghuang
{
public:
Codinghuang()
{
std::cout << "1" << std::endl;
}
Codinghuang(Codinghuang &coding)
{
std::cout << "2" << std::endl;
}
Codinghuang(const Codinghuang &coding)
{
std::cout << "3" << std::endl;
}
Codinghuang(Codinghuang &&coding)
{
std::cout << "4" << std::endl;
}
};
int main()
{
Codinghuang c1;
Codinghuang c2 = std::move(c1);
}
[root@aaeb2c267d0f test]# g++ -std=c++11 test.cpp
[root@aaeb2c267d0f test]# ./a.out
1
4
[root@aaeb2c267d0f test]#
#include <iostream>
class Codinghuang
{
public:
Codinghuang()
{
std::cout << "1" << std::endl;
}
Codinghuang(Codinghuang &coding)
{
std::cout << "2" << std::endl;
}
Codinghuang(const Codinghuang &coding)
{
std::cout << "3" << std::endl;
}
Codinghuang(Codinghuang &&coding)
{
std::cout << "4" << std::endl;
}
};
int main()
{
Codinghuang c1;
Codinghuang &c2 = c1;
}
[root@aaeb2c267d0f test]# g++ -std=c++11 test.cpp
[root@aaeb2c267d0f test]# ./a.out
1
[root@aaeb2c267d0f test]#
#include <iostream>
class Codinghuang
{
public:
Codinghuang()
{
std::cout << "1" << std::endl;
}
Codinghuang(Codinghuang &coding)
{
std::cout << "2" << std::endl;
}
Codinghuang(const Codinghuang &coding)
{
std::cout << "3" << std::endl;
}
Codinghuang(Codinghuang &&coding)
{
std::cout << "4" << std::endl;
}
};
int main()
{
Codinghuang c1;
Codinghuang &&c2 = std::move(c1);
}
[root@aaeb2c267d0f test]# g++ -std=c++11 test.cpp
[root@aaeb2c267d0f test]# ./a.out
1
[root@aaeb2c267d0f test]#