Click here to Skip to main content
15,171,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I like to define another function with different parameter , in this case the class pointer. Replace QTextEdit with QListView.
I can define another function using overload and copy the original function body

Is there another way ?

Is there another way ? 

Would "variable argument list " be a better / correct solution?

int Form_Widget_HCI::Redirect(int TEST,char *cmd,QTextEdit *text )

What I have tried:

I can define another function using overload and copy the original function body.
Updated 7-Nov-21 19:24pm

You can use function overloading, but it sounds like you're copying-pasting code, which is seldom a good idea. It may also depend on how QTextEdit and QListView are related. I'm not familiar with them, so you'd have to provide more information. Does one derive from the other? Do they have a common base class? Are they independent?
Overloading is an advanced technology in C++ but I recommend that you visit some Learn C++ tutorial to learn the basics. Without knowing the language or at least some skills you will get lost.

When you overload functions you should ensure that this overloading isnt casting objects to classes which isnt their identiy or it will crash later. Copying the function body is NONSENSE, but you must implement the details as suiting for you.

simple example for some printMessage() function.

printMessage(char *text);// input parameter must be char* or have some char* cast
printMessage(int value);// input must be int also implement that 
printMessage(ClassObject *obj);//  input must be of that class BUT also implement that special print

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900