Click here to Skip to main content
15,908,445 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
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 
Hi There,
Thanks for the replies.

First of all, apologizes for the previous chunck of code, it was all messed up and did not make much of sense.

The reason because a wanted to keep using 'pointers' instead of a 'vector container' was because of the initialization array.
[code]
arrDog [2][5] = {
{ Dog("00"), Dog("01"), Dog("02"), Dog("03"), Dog("04"), }
{ Dog("10"), Dog("11"), Dog("12"), Dog("13"), Dog("14") }
{......}
}
[/code]

In this case initialization array is very small and could easily be changed using vector declaration.
[code]
vector <Dog> arrDog[2];
arrDog[0].push_back(Dog("00"));
arrDog[0].push_back(Dog("01"));
etc...
[/code]
Any way to avoid this anoying declaration?


In my real case, arrDog is about [100][100] and the class used isn´t as simple as Dog.

That is the only reason, just avoid rewriting all the stuff again.
I know this is a *very* poor reason, please don´t flame at me Smile | :)

Althought I will use vectors I have found that using std::copy instead of memcpy things seems to work a bit better.

Does anybody know the gory details of std::copy?
Does std::copy calls copy-constructors members?
Using memcpy instead of std::copy I get rubish when printing stuff saved in vectors but I don´t get memory error, any reason?

[code]

#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;
}

Dog(const Dog& d) : nm("copy " + d.nm) {
cout << "Copy-constructed Dog " << nm << endl;
}

~Dog() {
cout << "Deleting Dog: " << *this << endl;
}

friend ostream&
operator<<(ostream& os, const Dog& d) {
return os << "[" << d.nm << "]";
}
};

class DogHouse {
Dog * m_p; //Dog Array
int m_n; //Number of dogs
string m_houseName;
public:
DogHouse (const Dog * p, const int n , const string& hn)
: m_p(new Dog[n * sizeof(Dog)]) ,m_n (n), m_houseName(hn) {
std::copy(p, p + n, m_p);
//memcpy(m_p, p , n * sizeof(Dog)); Uncomment this
}

DogHouse(const DogHouse& dh)
: m_p(new Dog[dh.m_n * sizeof(Dog)]), m_n(dh.m_n),
m_houseName(dh.m_houseName + " copy-constructed") {
std::copy(dh.m_p,dh.m_p+dh.m_n,m_p);
//memcpy(m_p, dh.m_p, dh.m_n * sizeof(Dog)); Uncomment this
}

~DogHouse() { delete [] m_p; }
friend ostream&
operator<<(ostream& os, const DogHouse& dh) {
os << "[" << dh.m_houseName << "] contains " << endl;
std::copy(dh.m_p,dh.m_p + dh.m_n,
std::ostream_iterator<Dog>(os,"\n"));
return os;
}
};

int main() {

Dog arrDog[4][5] = {
{ Dog("01"),Dog("02"),Dog("03"),Dog("04"),Dog("05") },
{ Dog("11"),Dog("12"),Dog("13"),Dog("14"),Dog("15") },
{ Dog("21"),Dog("22"),Dog("23"),Dog("24"),Dog("25") },
{ Dog("31"),Dog("32"),Dog("33"),Dog("34"),Dog("35") }
};

vector <DogHouse> HouseContainer;
HouseContainer.push_back(DogHouse(arrDog[0], 5 ," Dog Row 0 "));
HouseContainer.push_back(DogHouse(arrDog[1], 5 ," Dog Row 1 "));
HouseContainer.push_back(DogHouse(arrDog[3], 5 ," Dog Row 3 "));


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

[/code]

Regards
Carlos.
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 
QuestionIs there a tool that I can find all the bmp file in one directroy (include the bmp file in exe ,dll)? Pin
16-May-02 3:07
suss16-May-02 3:07 
AnswerRe: Is there a tool that I can find all the bmp file in one directroy (include the bmp file in exe ,dll)? Pin
16-May-02 6:49
suss16-May-02 6:49 
GeneralDebug ,Release build problem.. Pin
16-May-02 2:34
suss16-May-02 2:34 
GeneralRe: Debug ,Release build problem.. Pin
Chris Losinger16-May-02 3:18
professionalChris Losinger16-May-02 3:18 

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.