If you want to pass class instances (objects), you either use
void function(const MyClass& object){
// do something with object
}
or
void process(MyClass& object_to_be_changed){
// change member variables
}
On the other hand if you want to "pass" the class itself
template<class AnyClass>
void function_taking_class(){
// use static functions of AnyClass
AnyClass::count_instances();
// or create an object of AnyClass and use it
AnyClass object;
object.member = value;
}
// call it as
function_taking_class<MyClass>();
// or
function_taking_class<MyStruct>();
with
class MyClass{
int member;
//...
};
MyClass object1;
https://stackoverflow.com/questions/1896369/how-to-use-a-class-object-in-c-as-a-function-parameter
'Development > C++' 카테고리의 다른 글
Inline Funtion #2 - Syntax, Examples. (0) | 2022.03.26 |
---|---|
Inline function #1 (0) | 2022.03.26 |
2차원 배열과 포인터배열(2차원 문자배열) (0) | 2022.03.25 |
배열과 포인터(포인터로 배열 다루기 1.) (0) | 2022.03.25 |
[C언어] 포인터 장단점, 포인터와 배열의 차이 (0) | 2022.03.25 |