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. New class

New class

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
7 Posts 3 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.
  • B Offline
    B Offline
    bugDanny
    wrote on last edited by
    #1

    I'm trying to write a new class that is a derivative of CObject. The code all looks fine to me, but when I try to compile I get an error saying "constructor not allowed a return type", but I'm not trying to put a return type, or a return statement. Here's the code.

    In ClassNameOb.cpp:
    #include "stdafx.h"
    #include "ClassNameOb.h"
    ClassName::ClassName()
    {
    m_var->VarOne = m_var->VarTwo = m_var->VarThree = m_var->VarFour = m_var->VarFive = -1;
    m_otherVar = -1;
    }
    ClassName::~ClassName(){}
    In ClassNameOb.h:
    class ClassName : public CObject
    {
    protected:
    struct structType
    {
    int VarOne;
    int VarTwo;
    int VarThree;
    int VarFour;
    int VarFive;
    }*m_var;
    int m_otherVar;
    public:
    ClassName();
    ~ClassName();
    }

    And then I get an error pointing to the line with the first { bracket of the constructor saying, "constructors not allowed a return type". Why am I getting this error when I'm not even trying to return anything? Danny The stupidity of others amazes me!

    D 1 Reply Last reply
    0
    • B bugDanny

      I'm trying to write a new class that is a derivative of CObject. The code all looks fine to me, but when I try to compile I get an error saying "constructor not allowed a return type", but I'm not trying to put a return type, or a return statement. Here's the code.

      In ClassNameOb.cpp:
      #include "stdafx.h"
      #include "ClassNameOb.h"
      ClassName::ClassName()
      {
      m_var->VarOne = m_var->VarTwo = m_var->VarThree = m_var->VarFour = m_var->VarFive = -1;
      m_otherVar = -1;
      }
      ClassName::~ClassName(){}
      In ClassNameOb.h:
      class ClassName : public CObject
      {
      protected:
      struct structType
      {
      int VarOne;
      int VarTwo;
      int VarThree;
      int VarFour;
      int VarFive;
      }*m_var;
      int m_otherVar;
      public:
      ClassName();
      ~ClassName();
      }

      And then I get an error pointing to the line with the first { bracket of the constructor saying, "constructors not allowed a return type". Why am I getting this error when I'm not even trying to return anything? Danny The stupidity of others amazes me!

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

      You need:

      class ClassName : public CObject
      {
      ...
      };


      "Take only what you need and leave the land as you found it." - Native American Proverb

      B S 2 Replies Last reply
      0
      • D David Crow

        You need:

        class ClassName : public CObject
        {
        ...
        };


        "Take only what you need and leave the land as you found it." - Native American Proverb

        B Offline
        B Offline
        bugDanny
        wrote on last edited by
        #3

        Aaaahhh!!! How annoying! I wish it couldn've told me it was a stupid syntax error! Danny The stupidity of others amazes me!

        1 Reply Last reply
        0
        • D David Crow

          You need:

          class ClassName : public CObject
          {
          ...
          };


          "Take only what you need and leave the land as you found it." - Native American Proverb

          S Offline
          S Offline
          S Senthil Kumar
          wrote on last edited by
          #4

          The OP missed the semicolon at the end of the class declaration? Regards Senthil _____________________________ My Blog | My Articles | WinMacro

          B 1 Reply Last reply
          0
          • S S Senthil Kumar

            The OP missed the semicolon at the end of the class declaration? Regards Senthil _____________________________ My Blog | My Articles | WinMacro

            B Offline
            B Offline
            bugDanny
            wrote on last edited by
            #5

            OP? I assume you mean the compiler? In that case, yes, it missed it. How annoying! Danny The stupidity of others amazes me!

            S 1 Reply Last reply
            0
            • B bugDanny

              OP? I assume you mean the compiler? In that case, yes, it missed it. How annoying! Danny The stupidity of others amazes me!

              S Offline
              S Offline
              S Senthil Kumar
              wrote on last edited by
              #6

              OP, I *think*, stands for Original Poster. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

              B 1 Reply Last reply
              0
              • S S Senthil Kumar

                OP, I *think*, stands for Original Poster. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

                B Offline
                B Offline
                bugDanny
                wrote on last edited by
                #7

                Oh, thanks. Yes, and I feel dumb for having missed it. Danny The stupidity of others amazes me!

                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