나는이 특정 주제에 대해 많이 찾았습니다. 하나 이상의 객체에 대해 많은 수의 변수를 가져와 일련의 함수를 전달해야하므로이 방법이 최선의 방법이라고 생각합니다.struct를 C++에서 생성자 매개 변수로 전달
구조체가 정의되지 않은 클래스의 생성자에 구조체를 전달하고 싶습니다. 이것이 가능한가? 내 코드는 다음과 같습니다.
class myClass
{
protected:
double someVar;
.
.
public:
myClass(struct structName); //compiler is ok with this
myClass(); //default construct
};
struct structName
{
double someOtherVar;
.
.
};
myClass::myClass(??????) ///I don't know what goes here
{
someVar = structName.someOtherVar; ///this is what I want to do
}
EDIT : 클래스에서 구조체를 선언하고 해당 구조체를 매개 변수로 사용한다고 가정합니까?
초보자 용 C++ 서적을 읽어보십시오. 여기에 좋은 목록이 있습니다. http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list. – juanchopanza
구조체는 잊어 버리십시오. 그들은 당신의 목적을 위해 다른 어떤 유형과도 같습니다. 'int'에'int x'라고 쓰면,'structName'에'structName x'를 쓸 수 있습니다. 그게 전부 야. –