I am an undergraduate mathematics major. During office hours I asked a question to a professor which was not a homework problem, but which was related to a homework problem (and I had made the connection clear). He answered my question fine enough, but at the end he said, "My office hours are for students to ask about [course he is teaching] only," and he said my question was not relevant to the course.
So, I asked (as politely as possible), who in the department should I ask if I have a question (as he was clearly implying not to ask him anymore)? He said, ask your teacher if the question relates to his class, but not otherwise.
Obviously I understand the importance of self-study, but am I expected to not ask anyone for advice on any questions that aren't word-for-word out of the textbook or problem set?
What is the typical attitude of professors toward students asking somewhat tangential but not totally off-topic questions? Is this normal behavior? I want to have realistic expectations for my professors in the future. I'm an underclassman and relatively new to the field of mathematics so maybe I just have wrong expectations right now. Hopefully some of you who are more experienced in academia can help me out here.
Edit: There was no one else in line after me to see the professor at office hours.