Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. C++ Coding help Needed

C++ Coding help Needed

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    waiwai933
    wrote on last edited by
    #1

    I have this one line in my C++ code that I'm using, but it says I need a initializer before the word "main". I took C++ a couple of years ago, so I naturally forgot what an initializer is, but I'm pretty sure that it's not int. Can anybody help? Code: int __cdecl main(int argc, const char* argv[]) {

    S R D 3 Replies Last reply
    0
    • W waiwai933

      I have this one line in my C++ code that I'm using, but it says I need a initializer before the word "main". I took C++ a couple of years ago, so I naturally forgot what an initializer is, but I'm pretty sure that it's not int. Can anybody help? Code: int __cdecl main(int argc, const char* argv[]) {

      S Offline
      S Offline
      sudhir marni
      wrote on last edited by
      #2

      Y u've mentioned __cdecl? Its implicit and return some value.

      1 Reply Last reply
      0
      • W waiwai933

        I have this one line in my C++ code that I'm using, but it says I need a initializer before the word "main". I took C++ a couple of years ago, so I naturally forgot what an initializer is, but I'm pretty sure that it's not int. Can anybody help? Code: int __cdecl main(int argc, const char* argv[]) {

        R Offline
        R Offline
        Rajkumar R
        wrote on last edited by
        #3

        waiwai933 wrote:

        so I naturally forgot what an initializer is,

        May be true :) , AFAIK initializers are for data types not for function, which gives initial values to variables.

        waiwai933 wrote:

        but I'm pretty sure that it's not int.

        iam not sure couple of years ago it was so. :) return of main is same as calling exit function in main, it is used to return the success code of the application and it is int. u can avoid returning any value if the type of main is void. As a side note C++ doesnot assume default int for function return type (may be this is ur "pretty sure"). u can check whether main is using int by giving return type like double (where sizeof(return type) > sizeof (int) or user type)

        waiwai933 wrote:

        this one line in my C++ code

        In this line of C++ code, i think no issues. can u state what is the exact error statement.

        waiwai933 wrote:

        Can anybody help?

        I suspect some code above or below this function causing the error say

        struct MyStruct
        {
        } // missing ;
        int __cdecl main(int argc, const char* argv[])
        {

        in this case compiler says error in return type as it takes MyStruct as return type.

        1 Reply Last reply
        0
        • W waiwai933

          I have this one line in my C++ code that I'm using, but it says I need a initializer before the word "main". I took C++ a couple of years ago, so I naturally forgot what an initializer is, but I'm pretty sure that it's not int. Can anybody help? Code: int __cdecl main(int argc, const char* argv[]) {

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Unless you are passing arguments to main() and are returning a value to the command interpreter, you could simplify things by using:

          void main( void )
          {
          ...
          }

          "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups