Skip to content

Instantly share code, notes, and snippets.

@huanghantao
Last active January 2, 2020 08:34
Show Gist options
  • Save huanghantao/089c409060585208f51601be1d4bb0c1 to your computer and use it in GitHub Desktop.
Save huanghantao/089c409060585208f51601be1d4bb0c1 to your computer and use it in GitHub Desktop.

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]#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment