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. Object Oriented Problem.

Object Oriented Problem.

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpoopannouncement
8 Posts 5 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.
  • R Offline
    R Offline
    RobNO
    wrote on last edited by
    #1

    Hey everyone, my problem is I keep getting compile errors and i can not pin point the problem errors: 2>c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\countptr.hpp(37) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 2> c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\countptr.hpp(71) : see reference to class template instantiation 'CountedPtr<T>' being compiled 2>c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\countptr.hpp(37) : error C2143: syntax error : missing ',' before '&' 2>c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\countptr.hpp(37) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 2> c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\refsem1.cpp(11) : see reference to class template instantiation 'CountedPtr<T>' being compiled 2> with 2> [ 2> T=int 2> ] 2>c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\countptr.hpp(37) : error C2143: syntax error : missing ',' before '&' .hpp file

    //ect/countprt.hpp

    #ifndef COUNTED_PTR_HPP
    #define COUNTED_PTR_HPP

    /*class template for smart pointer with reference semantics
    * -destroys the object that is referred to when the last CountedPTr that refers to it is destroyed
    */
    template <typename T>
    class CountedPtr
    {
    private:
    T* ptr; //pointer to the actual object
    long* count; //reference to the number of pointers that refer to it

    public:
    //initialize with ordinary pointer
    // -p has to be a value returned by new
    explicit CountedPtr(T* p = 0) : ptr(p), count(new long(1))
    {

    }
    
    //copy constructor
    CountedPtr(const CountedPtr<T>& p) throw() : ptr(p.ptr), count(p.count)		//copy object and counter
    {
    	++count;																//increment number of references
    }
    
    //destructor
    ~CountedPtr() throw()
    {
    	release();		//release reference to the object
    }
    
    //assignment
    CountedPtr<T>& operator= (const CounterPtr<T>& p) throw ()
    {
    	if (this != &p)		//if not a reference to itself
    	{
    		release();		//release reference to old object
    		ptr = p.ptr;	//copy new object
    		count = p.count;//copy counter
    
    S P S 3 Replies Last reply
    0
    • R RobNO

      Hey everyone, my problem is I keep getting compile errors and i can not pin point the problem errors: 2>c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\countptr.hpp(37) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 2> c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\countptr.hpp(71) : see reference to class template instantiation 'CountedPtr<T>' being compiled 2>c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\countptr.hpp(37) : error C2143: syntax error : missing ',' before '&' 2>c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\countptr.hpp(37) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 2> c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\refsem1.cpp(11) : see reference to class template instantiation 'CountedPtr<T>' being compiled 2> with 2> [ 2> T=int 2> ] 2>c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\countptr.hpp(37) : error C2143: syntax error : missing ',' before '&' .hpp file

      //ect/countprt.hpp

      #ifndef COUNTED_PTR_HPP
      #define COUNTED_PTR_HPP

      /*class template for smart pointer with reference semantics
      * -destroys the object that is referred to when the last CountedPTr that refers to it is destroyed
      */
      template <typename T>
      class CountedPtr
      {
      private:
      T* ptr; //pointer to the actual object
      long* count; //reference to the number of pointers that refer to it

      public:
      //initialize with ordinary pointer
      // -p has to be a value returned by new
      explicit CountedPtr(T* p = 0) : ptr(p), count(new long(1))
      {

      }
      
      //copy constructor
      CountedPtr(const CountedPtr<T>& p) throw() : ptr(p.ptr), count(p.count)		//copy object and counter
      {
      	++count;																//increment number of references
      }
      
      //destructor
      ~CountedPtr() throw()
      {
      	release();		//release reference to the object
      }
      
      //assignment
      CountedPtr<T>& operator= (const CounterPtr<T>& p) throw ()
      {
      	if (this != &p)		//if not a reference to itself
      	{
      		release();		//release reference to old object
      		ptr = p.ptr;	//copy new object
      		count = p.count;//copy counter
      
      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      First, it would have been helpful if you had marked the error locations for us :rolleyes: I counted to line 37 and found this:

      //assignment
      CountedPtr<T>& operator= (const CounterPtr<T>& p) throw ()
      {
      if (this != &p) //if not a reference to itself
      {
      release(); //release reference to old object
      ptr = p.ptr; //copy new object
      count = p.count;//copy counter
      ++*count;
      }
      return *this;
      }

      Have a look at the spelling where I've underlined.

      Steve

      R P 2 Replies Last reply
      0
      • S Stephen Hewitt

        First, it would have been helpful if you had marked the error locations for us :rolleyes: I counted to line 37 and found this:

        //assignment
        CountedPtr<T>& operator= (const CounterPtr<T>& p) throw ()
        {
        if (this != &p) //if not a reference to itself
        {
        release(); //release reference to old object
        ptr = p.ptr; //copy new object
        count = p.count;//copy counter
        ++*count;
        }
        return *this;
        }

        Have a look at the spelling where I've underlined.

        Steve

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

        Thank you very much! Next Time I will try to indicate where the error is. :laugh: RobNO.

        1 Reply Last reply
        0
        • R RobNO

          Hey everyone, my problem is I keep getting compile errors and i can not pin point the problem errors: 2>c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\countptr.hpp(37) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 2> c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\countptr.hpp(71) : see reference to class template instantiation 'CountedPtr<T>' being compiled 2>c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\countptr.hpp(37) : error C2143: syntax error : missing ',' before '&' 2>c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\countptr.hpp(37) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 2> c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\refsem1.cpp(11) : see reference to class template instantiation 'CountedPtr<T>' being compiled 2> with 2> [ 2> T=int 2> ] 2>c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\countptr.hpp(37) : error C2143: syntax error : missing ',' before '&' .hpp file

          //ect/countprt.hpp

          #ifndef COUNTED_PTR_HPP
          #define COUNTED_PTR_HPP

          /*class template for smart pointer with reference semantics
          * -destroys the object that is referred to when the last CountedPTr that refers to it is destroyed
          */
          template <typename T>
          class CountedPtr
          {
          private:
          T* ptr; //pointer to the actual object
          long* count; //reference to the number of pointers that refer to it

          public:
          //initialize with ordinary pointer
          // -p has to be a value returned by new
          explicit CountedPtr(T* p = 0) : ptr(p), count(new long(1))
          {

          }
          
          //copy constructor
          CountedPtr(const CountedPtr<T>& p) throw() : ptr(p.ptr), count(p.count)		//copy object and counter
          {
          	++count;																//increment number of references
          }
          
          //destructor
          ~CountedPtr() throw()
          {
          	release();		//release reference to the object
          }
          
          //assignment
          CountedPtr<T>& operator= (const CounterPtr<T>& p) throw ()
          {
          	if (this != &p)		//if not a reference to itself
          	{
          		release();		//release reference to old object
          		ptr = p.ptr;	//copy new object
          		count = p.count;//copy counter
          
          P Offline
          P Offline
          Peter_in_2780
          wrote on last edited by
          #4

          RobNO wrote:

          //assignment
          CountedPtr& operator= (const CounterPtr& p) throw ()
          {

          Spelling the class name consistently would probably help...

          Software rusts. Simon Stephenson, ca 1994.

          1 Reply Last reply
          0
          • S Stephen Hewitt

            First, it would have been helpful if you had marked the error locations for us :rolleyes: I counted to line 37 and found this:

            //assignment
            CountedPtr<T>& operator= (const CounterPtr<T>& p) throw ()
            {
            if (this != &p) //if not a reference to itself
            {
            release(); //release reference to old object
            ptr = p.ptr; //copy new object
            count = p.count;//copy counter
            ++*count;
            }
            return *this;
            }

            Have a look at the spelling where I've underlined.

            Steve

            P Offline
            P Offline
            Peter_in_2780
            wrote on last edited by
            #5

            You got your message posted while I was still counting lines!

            Software rusts. Simon Stephenson, ca 1994.

            S T 2 Replies Last reply
            0
            • P Peter_in_2780

              You got your message posted while I was still counting lines!

              Software rusts. Simon Stephenson, ca 1994.

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #6

              I actually pasted it into an editor which shows line numbers...

              Steve

              1 Reply Last reply
              0
              • R RobNO

                Hey everyone, my problem is I keep getting compile errors and i can not pin point the problem errors: 2>c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\countptr.hpp(37) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 2> c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\countptr.hpp(71) : see reference to class template instantiation 'CountedPtr<T>' being compiled 2>c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\countptr.hpp(37) : error C2143: syntax error : missing ',' before '&' 2>c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\countptr.hpp(37) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 2> c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\refsem1.cpp(11) : see reference to class template instantiation 'CountedPtr<T>' being compiled 2> with 2> [ 2> T=int 2> ] 2>c:\users\rob\school work\information technology\computer programming with c++\projects\etc\ect_1\countptr.hpp(37) : error C2143: syntax error : missing ',' before '&' .hpp file

                //ect/countprt.hpp

                #ifndef COUNTED_PTR_HPP
                #define COUNTED_PTR_HPP

                /*class template for smart pointer with reference semantics
                * -destroys the object that is referred to when the last CountedPTr that refers to it is destroyed
                */
                template <typename T>
                class CountedPtr
                {
                private:
                T* ptr; //pointer to the actual object
                long* count; //reference to the number of pointers that refer to it

                public:
                //initialize with ordinary pointer
                // -p has to be a value returned by new
                explicit CountedPtr(T* p = 0) : ptr(p), count(new long(1))
                {

                }
                
                //copy constructor
                CountedPtr(const CountedPtr<T>& p) throw() : ptr(p.ptr), count(p.count)		//copy object and counter
                {
                	++count;																//increment number of references
                }
                
                //destructor
                ~CountedPtr() throw()
                {
                	release();		//release reference to the object
                }
                
                //assignment
                CountedPtr<T>& operator= (const CounterPtr<T>& p) throw ()
                {
                	if (this != &p)		//if not a reference to itself
                	{
                		release();		//release reference to old object
                		ptr = p.ptr;	//copy new object
                		count = p.count;//copy counter
                
                S Offline
                S Offline
                Sarath C
                wrote on last edited by
                #7

                Watch-out for typos in your program in the operator =, you've used CounterPointer instead of CountedPointer

                -Sarath.

                My blog - Sharing My Thoughts

                Rate the answers and close your posts if it's answered

                1 Reply Last reply
                0
                • P Peter_in_2780

                  You got your message posted while I was still counting lines!

                  Software rusts. Simon Stephenson, ca 1994.

                  T Offline
                  T Offline
                  ThatsAlok
                  wrote on last edited by
                  #8

                  time to use Notepad++ :-)

                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
                  Never mind - my own stupidity is the source of every "problem" - Mixture

                  cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

                  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