Click here to Skip to main content
16,006,514 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CListCtrl set multiselection Pin
KaЯl16-May-02 5:31
KaЯl16-May-02 5:31 
GeneralRe: CListCtrl set multiselection Pin
Zizilamoroso16-May-02 5:38
Zizilamoroso16-May-02 5:38 
GeneralRe: CListCtrl set multiselection Pin
Zizilamoroso16-May-02 5:41
Zizilamoroso16-May-02 5:41 
GeneralRe: CListCtrl set multiselection Pin
KaЯl16-May-02 5:52
KaЯl16-May-02 5:52 
GeneralRe: CListCtrl set multiselection Pin
Jean-Marc Molina3-Oct-03 1:21
Jean-Marc Molina3-Oct-03 1:21 
QuestionDynamically Creat icons? Pin
jimNLX16-May-02 4:38
jimNLX16-May-02 4:38 
AnswerRe: Dynamically Creat icons? Pin
Shog916-May-02 17:22
sitebuilderShog916-May-02 17:22 
Generalcopy-constructor issue Pin
Carlos Sánchez García16-May-02 4:29
Carlos Sánchez García16-May-02 4:29 
Hi There,
Can anyone explainme why this piece of code doesn´t work?
I'm running VC 6.0 / W2K.

#include <string>
#include <iostream>
#include <vector>
#include <algorithm>

using std::string;
using std::cout;
using std::vector;
using std::ostream;
using std::endl;

class Dog {
string nm;
public:
Dog ( void ) : nm("NO NAME") {}
Dog(const string& name) : nm(name) {
cout << "Creating Dog: " << *this << endl;
}
// Synthesized copy-constructor & operator=
// are correct.
// Create a Dog from a Dog pointer:
Dog(const Dog* dp, const string& msg)
: nm(dp->nm + msg) {
cout << "Copied dog " << *this << " from "
<< *dp << endl;
}
~Dog() {
cout << "Deleting Dog: " << *this << endl;
}
void rename(const string& newName) {
nm = newName;
cout << "Dog renamed to: " << *this << endl;
}
friend ostream&
operator<<(ostream& os, const Dog& d) {
return os << "[" << d.nm << "]";
}
};

class DogHouse {
Dog* p; //Dog array
string houseName;
public:
DogHouse (Dog * lpDog, const size_t size) : p(new Dog[size]) {
memcpy(p, lpDog, size);
}
DogHouse(Dog* dog, const string& house)
: p(dog), houseName(house) {}
DogHouse(const DogHouse& dh)
: p(new Dog(dh.p, " copy-constructed")),
houseName(dh.houseName
+ " copy-constructed") {}
DogHouse& operator=(const DogHouse& dh) {
// Check for self-assignment:
if(&dh != this) {
p = new Dog(dh.p, " assigned");
houseName = dh.houseName + " assigned";
}
return *this;
}

void renameHouse(const string& newName) {
houseName = newName;
}
Dog* getDog() const { return p; }
~DogHouse() { delete p; }
friend ostream&
operator<<(ostream& os, const DogHouse& dh) {
return os << "[" << dh.houseName
<< "] contains " << *dh.p;
}
};

int main() {

Dog arrDog[2][10] = {
{ Dog("01"),Dog("02"),Dog("03"),Dog("04"),Dog("05") },
{ Dog("11"),Dog("12"),Dog("13"),Dog("14"),Dog("15") }
};
vector <DogHouse> HouseContainer;
/*HouseContainer.push_back(DogHouse(new Dog(arrDog[0]," From static array"), "Static array"));*/
HouseContainer.push_back(DogHouse(arrDog[0], sizeof(Dog)));
/*HouseContainer.push_back(DogHouse(new Dog("Kido"), "KidoHouse"));*/

std::copy(HouseContainer.begin(),
HouseContainer.end(),
std::ostream_iterator<DogHouse>(cout,"\n"));

return 1;
} ///Unsure | :~


Assert Memory error raised when trying to do bookeeping.
I guess the problem is how static array of 'Dogs' is copied (using memcpy) to the new object 'DogHouse'.

Can anyone tell me how can I make this idea work without changing the interface, I mean I would like to keep using Dog pointer to store the array of Dog instead of a vector or other containers.

Thanks in advanced.
Carlos.

GeneralRe: copy-constructor issue Pin
Joaquín M López Muñoz16-May-02 5:02
Joaquín M López Muñoz16-May-02 5:02 
GeneralRe: copy-constructor issue Pin
Mike Nordell16-May-02 5:33
Mike Nordell16-May-02 5:33 
GeneralRe: copy-constructor issue Pin
Maxwell Chen16-May-02 19:26
Maxwell Chen16-May-02 19:26 
GeneralRe: copy-constructor issue Pin
Carlos Sánchez García16-May-02 23:45
Carlos Sánchez García16-May-02 23:45 
GeneralRe: copy-constructor issue Pin
Mike Nordell17-May-02 1:30
Mike Nordell17-May-02 1:30 
GeneralRecording Audio Pin
AJ12316-May-02 4:15
AJ12316-May-02 4:15 
GeneralRe: Recording Audio Pin
redeemer16-May-02 4:17
redeemer16-May-02 4:17 
QuestionHow do i assign a string to each item in a ListView? Pin
redeemer16-May-02 4:10
redeemer16-May-02 4:10 
AnswerRe: How do i assign a string to each item in a ListView? Pin
Chris Losinger16-May-02 5:03
professionalChris Losinger16-May-02 5:03 
GeneralRe: How do i assign a string to each item in a ListView? Pin
redeemer16-May-02 5:08
redeemer16-May-02 5:08 
GeneralRe: How do i assign a string to each item in a ListView? Pin
Chris Losinger16-May-02 5:17
professionalChris Losinger16-May-02 5:17 
GeneralRe: How do i assign a string to each item in a ListView? Pin
redeemer16-May-02 5:38
redeemer16-May-02 5:38 
GeneralRe: How do i assign a string to each item in a ListView? Pin
Chris Losinger16-May-02 6:36
professionalChris Losinger16-May-02 6:36 
GeneralDialogs question Pin
BlackRider16-May-02 3:50
BlackRider16-May-02 3:50 
GeneralRe: Dialogs question Pin
Prem Kumar16-May-02 3:48
Prem Kumar16-May-02 3:48 
GeneralRe: Dialogs question Pin
Chris Losinger16-May-02 3:56
professionalChris Losinger16-May-02 3:56 
GeneralRe: Dialogs question Pin
Nish Nishant16-May-02 4:04
sitebuilderNish Nishant16-May-02 4:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.