+ 1

Issues with code

#include <iostream> struct Grapher; class Direction{ protected: char directionType; public: getDirectionType(){ return directionType; } }; class Down : public Direction{ public: Down(char down) { directionType = down; } }; class Right : public Direction{ public: Right(char right) { directionType = right; } }; class Left : public Direction{ public: Left(char left) { directionType = left; } }; int main() { return 0; } struct Grapher{ if(Direction::getDirectionType == Left::left) std::cout << "<"; if(Direction::getDirectionType == Right::right) std::cout << ">"; if(Direction::getDirectionType == Down::down) std::cout << "|"; }; Note: this code musn't outputs anything right now.

16th Aug 2018, 2:57 PM
Oleg Storm
Oleg Storm - avatar
5 ответов
+ 1
putting all the if statements inside a constructor or any other function fixes one problem. Next problem is that "Left::left" would not work, as there isnt any variable named "left" in the "Left" class (one that is created in the constructor will work only inside the constructor)
16th Aug 2018, 3:32 PM
Data
Data - avatar
+ 1
In this line: struct Grapher{ it says unexpected id before if statement🤔 You can test by yourself, ofcourse.
16th Aug 2018, 2:59 PM
Oleg Storm
Oleg Storm - avatar
+ 1
Data thanks a lot, it really helps👍
16th Aug 2018, 3:52 PM
Oleg Storm
Oleg Storm - avatar
0
hmm, shouldnt if statements be inside of functions in structs just as in classes?
16th Aug 2018, 3:20 PM
Data
Data - avatar
0
getDirectionType() also doesent seem to have a type assigned to it, but it needs to have one since it returns a value. I recomend you put "char" before getDirectionType to specify its type, since it returns a char
16th Aug 2018, 3:28 PM
Data
Data - avatar