2

When I attempt to post the following question:

Hey, I recently started C++ using SDL2 after a long time of C# (XNA and Unity3D)

I don't quite get how I create objects in my project, to explain what I mean..

In C# you can create a class SphereObject(as different file (SphereObject.cs) which then you can (from any class) do this (example in MainClass.cs)

    namespace MyProject
     {
         class MainClass
         {
             SphereObject sphere;
             MainClass()
             {
                sphere = new SphereObject();
             }
          }
     }

Which would then call the constructor in SphereObject.cs

This essentially gives me an object of type SphereObject;

now maybe this is a big question.. But try to explain it as easy as you can

How do I do this in c++?

Current I have

main.cpp (which is my entrypoint) MyMain.cpp MyMain.h

in the constructor of main I would like to do

MyMain mainClass = new MyMain();

which would then call the constructor of MyMain.cpp.

I've searched google around a bit and even saw a few stackoverflow refs, but they're all not what I need (they have 1 huge file with different classes in it.. which is already possible but not what I need (way too obscuring)

I get an error that "Post contains code not formatted correctly". What can I do about that?

4
  • @Qantas94Heavy seems you have removed code block that was there originally. Could you bring it back? Sadly, I can't find a way to put code block inside a quote (hardly needed it).
    – Mołot
    Nov 20 '13 at 12:51
  • @Mołot: looks fine on my computer, weird. Maybe just revert it to the original? Nov 20 '13 at 12:56
  • Now, after edit by user3012995, it does look acceptable on mine too. Actually, your version seen as revision looks even better than current one. But when I was looking at it in a regular way, it wasn't :( Of course I'm perfectly OK to assume it was a glitch on my computer if you say you have seen it OK.
    – Mołot
    Nov 20 '13 at 12:59
  • @Mołot: I was looking at revisions just now, so I'm not sure whether it's broken on the actual post. Nov 20 '13 at 13:04
2

First of all you might want to check your spelling/punctuation/grammar - fixing this up will make your post look significantly better.

Anyway, to the actual issue. This seems to trigger the checker:

main.cpp (which is my entrypoint)
MyMain.cpp
MyMain.h

Change that to:

- main.cpp (which is my entrypoint)
- MyMain.cpp
- MyMain.h

When testing with a 1 rep sockpuppet account, this stopped the error message. Regardless, there are numerous improvements to the formatting that can be done - this gives a much better impression of putting effort into your question.

2
  • Yes that is it, I don't see why we can't just use code brackets here [code] //code here [/code] is alot easier
    – Themperror
    Nov 20 '13 at 13:10
  • 1
    @Themperror you can use `code ticks` if you want ;)
    – Mołot
    Nov 20 '13 at 13:26
1

The obvious answer would be:

reformat your post

Some tips:

The main issues that cause the validation logic to think your post contains code which is not formatted are the number of short (less than 80 characters), non-code (not starting with four spaces) lines that contain stuff like dots ., parentheses () or even end with a semicolon ;.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .