나는 간단한 클래스를 가지고있다.컴파일러가 make -shared()가 l- 값을 예상 함
simple_class.h 맥북에서 실행
class SimpleClass {
private:
int d_ii;
int d_jj;
public:
SimpleClass() : d_ii(40), d_jj(10) {}
SimpleClass(const int ii, const int jj) : d_ii(ii), d_jj(jj) {}
};
test.t.cpp
//----------------------------------------------------------------//
//
// Test Program
#include <memory>
#include <simple_class.h>
int main (int argc, char * argv[])
{
SimpleClass sc1;
SimpleClass sc2(10, 20);
std::shared_ptr<SimpleClass> spSc1(new SimpleClass(10,12));
int ii = 10;
int jj = 16;
std::shared_ptr<SimpleClass> spSc2 = std::make_shared<SimpleClass> (ii, jj);
std::shared_ptr<SimpleClass> spSc3 = std::make_shared<SimpleClass> (10, 16);
return 0;
}
: 그 생성자 중 하나는 인수로 두 int
값을 사용합니다.
gcc -o test -I. test.t.cpp -lstdc++
그러나이 오류가 발생합니다 : 여기 내 컴파일 문은
test.t.cpp:18:41: error: no matching function for call to 'make_shared'
std::shared_ptr<SimpleClass> spSc3 = std::make_shared<SimpleClass> (10, 16);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:4708:1: note:
candidate function [with _Tp = SimpleClass, _A0 = int, _A1 = int] not viable: expects an l-value for 1st
argument
make_shared(_A0& __a0, _A1& __a1)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:4692:1: note:
candidate function template not viable: requires 0 arguments, but 2 were provided
make_shared()
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:4700:1: note:
candidate function template not viable: requires single argument '__a0', but 2 arguments were provided
make_shared(_A0& __a0)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:4716:1: note:
candidate function template not viable: requires 3 arguments, but 2 were provided
make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
^
1 error generated.
그래서 제 질문은, 왜하지 않습니다 make_shared()
작업이 사용? 이 이유
int ii = 10;
int jj = 16;
std::shared_ptr<SimpleClass> spSc2 = std::make_shared<SimpleClass> (ii, jj);
사람이 설명 할 수 : L 자 값 버전이 이 컴파일 않습니다 통과 것을
는std::shared_ptr<SimpleClass> spSc2 = std::make_shared<SimpleClass>(10, 16);
주의 사항?
내 생성자가 인수를 const
으로 선언합니다 (필수는 아니지만). examples given here은 make_shared()
으로 상수를 전달합니다.
[재생할 수 없음] (http://coliru.stacked-crooked.com/a/d582117f25211a0d) – NathanOliver
사용중인 컴파일러 버전은 무엇입니까? – NathanOliver
Dino @ MacDino : ~/code/test $ gcc -v --prefix =/응용 프로그램/Xcode.app/내용/개발자/usr --with-gxx-include-dir =/usr/include/C++/4.2.1 Apple LLVM 버전 7.0.2 (clang-700.1.81) 대상 : x86_64-apple-darwin14.5.0 스레드 모델 : posix –