Due to my limited experience with C++, I'm making a parallel to Java here, but I believe I have preserved the point
Don't do it isn't an answer
Only during the last week I've committed several atrocities with swing by (ab)using various layouts and mouse listeners about which I'd rather not talk about. Under normal conditions I'd respond to similar stuff with "Don't do it" and I understand that point of view completely. However, sometimes the scale won't allow you to do everything in a pretty and good way ("nice" solution might only work for datasets which count hundreds of points, but you need completely different approach possibly with some homemade stuff for hundreds of thousands), other times that thing won't play nice with other stuff you have previously implemented, or you'd like to avoid touching some inherited codebase unless absolutely necessary.
Googling for my issues, I have come across several "Don't do it" answers on SO suggesting some alternative and usually much simpler approach. The problem is, that simpler approach doesn't work for me and more importantly it isn't an answer. Sure, it might have helped OP (and sometimes not even that), but the priority of SO should be helping the community. The moment it's one of the top of Google results, it's not only relevant to the OP. If you want to give a suggestion, do so in comments. But when I come across something you've written several years later, please don't disappoint me with a non-answer.
My vote goes to treating all questions equally whether they ask for the "right" thing or not. If it's a duplicate mark it as such. If it asks for some overly complicated code, explain the principle and point to additional resources if necessary (having a STL implementation somewhere around is always useful; I know I have learned some stuff from standard implementations, though I must admit Java code is much prettier than C++ templates). I don't remember writing a snippet longer than 5 lines for any SO answer, except when I have already had the required code in some project so the only thing I needed to do was digging it up. A few paragraphs should be enough for any answer, and if anything homework assignments should be simpler in their essence.
And, well, if someone needs help with his/her homework, why shouldn't he ask for it on SO if it's warranted? So if it's a legit question, I see nothing wrong with guiding someone to the solution. Of course code dumps do no good and should be discouraged; they only increase cognitive load of understanding the code if you actually need to commit it somewhere.