Object Oriented Problem.
-
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 itpublic:
//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
-
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 itpublic:
//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
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
-
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
-
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 itpublic:
//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
RobNO wrote:
//assignment
CountedPtr& operator= (const CounterPtr& p) throw ()
{Spelling the class name consistently would probably help...
Software rusts. Simon Stephenson, ca 1994.
-
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
You got your message posted while I was still counting lines!
Software rusts. Simon Stephenson, ca 1994.
-
You got your message posted while I was still counting lines!
Software rusts. Simon Stephenson, ca 1994.
I actually pasted it into an editor which shows line numbers...
Steve
-
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 itpublic:
//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
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
-
You got your message posted while I was still counting lines!
Software rusts. Simon Stephenson, ca 1994.
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" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You