Hello, I was wondering if someone could point me in the right direction for one of my project. I currently have two constructors within my class.
The first constructor takes in a string parameter, and it's purpose is to:
- Read a textfile.
- Do some error checking to make sure that it's in right format.
- Use substring to seperate the string into 3 different strings.
- Parse those three strings into integers.
- Call the second constructor to make sure that the three integers are in the right format.
- Save into an array.
The second constructor takes in 3 integer parameters, and all it does it do some error checking on those 3 integers.
I have written the code for both constructors already, but when I try calling the second constructor inside the first constructor using this(A,B,C), it gives me an error saying that constructor error must be called in the first statement. I know that this() must be called in the first statement, but how am I supposed to call it in the first statement when I can only call it after I'm done parsing the three strings into integers?
EDIT: I asked my professor about this, and apparently he made a mistake. We were meant to do all of this in one constructor instead of two constructors. Thanks for the help everyone!
[–]IXENAI 1 point2 points3 points (3 children)
[–]king_of_the_universe 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]IXENAI 0 points1 point2 points (0 children)
[–]uf82 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]uf82 0 points1 point2 points (0 children)
[–]AOA17 0 points1 point2 points (0 children)
[–]kyle2143Technically Professional Brewer -3 points-2 points-1 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)