Answer the question
In order to leave comments, you need to log in
What is the correct way to use typedef?
If in a class using typedef I create an "alias" for some built-in type, and then I specify the "alias" as a return type or as an argument for any member method, then the compiler gives an error.
Example:
typedef unsigned int DigitArea;
typedef char Symbol;
typedef char* SymbolicArea;
class String final{
private:
SymbolicArea Literal;
DigitArea Length;
DigitArea Volume;
DigitArea IdentifyLength(const SymbolicArea str);
DigitArea IdentifyLength(SymbolicArea str);
«DigitArea String::IdentifyLength(SymbolicArea)» cannot be overloaded with «DigitArea String::IdentifyLength(SymbolicArea)»
19 | DigitArea IdentifyLength(SymbolicArea str);
|
Answer the question
In order to leave comments, you need to log in
Remove the penultimate line. The compiler is complaining about the duplicate method declaration, IdentifyLength,
not the typedef
. typedef
By the way, in the new code, you should use : instead of using
:
Or better yet, use the types from the default. For example:
using DigitArea = unsigned int;
using DigitArea = std::int64_t;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question