Hi, all
I have a question about the pointer and here is my header file and cpp file.
and cpp fileCode:// Integer.h #ifndef INTEGER_H #define INTEGER_H class Integer { public: Integer() { value = 0;} // set value is 0 in the default constructor Integer( int intVal ); // create a value "intVal" in this constructor ~Integer(); // Destructor int getInteger() const; void setInteger( int newInteger ); Integer& operator=( const Integer& rhInteger ); private: int* value; //replace from int value; }; #endif
However, when i try to compile it, it has 3 errors.Code:// Integer.cpp #include <cstdlib> #include "integer.h" Integer::Integer( int intVal) { value = intVal; } int Integer::getInteger() const { return value; } void Integer::setInteger( int newInteger ) { value = newInteger; } Integer& Integer::operator=( const Integer& rhInt ) { Integer copy(rhInt); int* temp = value; value = copy.value; //steal the new deep copy copy.value = temp; return *this; }
c:\documents and settings\misia\my documents\homework\cosc2406\pointers\integer.cpp(7 ) : error C2440: '=' : cannot convert from 'int' to 'int *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\misia\my documents\homework\cosc2406\pointers\integer.cpp(1 2) : error C2440: 'return' : cannot convert from 'int *const ' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
c:\documents and settings\misia\my documents\homework\cosc2406\pointers\integer.cpp(1 7) : error C2440: '=' : cannot convert from 'int' to 'int *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
Can someone give me some advises how to correct it?
Thanks![]()
![]()



LinkBack URL
About LinkBacks




