![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
This may seem circular, but raw memory is memory that your program is not treating as if it contains a particular type of data (eg an int, a pointer, a float, a struct, an enum, etc etc).
Let's say we have a type SomeType. SomeType may represent basic types (int, float, etc) or it may represent a class type that has a constructor. When you declare a SomeType, for example; SomeType x; Another example is when you are doing dynamic memory allocation using malloc(). For example; void *something = malloc(some_size);
short *c = (short *)something; // typecast not necessary in CIn C++, a rough equivalent of malloc() is operator new. Operator new actually works in two phases: a call to a function named operator new() and then (for a type with a constructor) invoking a constructor (or, if creating an array of objects, invoking the constructor multiple times). For example, by default SomeType *x = new SomeType; ::operator new (sizeof SomeType) |
|
|
|
|
|
#12 | |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
Quote:
#include<iostream>
using namespace std;
class X
{
private:
int a;
public:
X(int b)
{
a=b;
cout<<"X invoked"<<endl;
}
void show()
{
cout<<"a=="<<a<<endl;
}
};
int main()
{
X a(10);
X b=X(20);
a.show();
b.show();
return 0;
}X b=X(20);
__________________
PFO - My daily dose of technology. |
|
|
|
|
|
|
#13 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
Quote:
The only circumstance in which a compiler generated copy constructor will create a bitwise copy is for classes that have no base classes and all data members are basic types (int, double, enums, pointers, etc). |
|
|
|
|
|
|
#14 |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
Thanks for clearing up the confusion.
__________________
PFO - My daily dose of technology. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|