Monday, April 28, 2014

error while using the function size ()

Newsgroup: comp.lang.c++

Subject: error while using the function size ()

From: Milica Milojevic <milicam363@...>

Date: Mon, 28 Apr 2014 04:09:11 -0700 (PDT)



Hi,



I have created a list called measuresQueue (list<pssMeasure *> measuresQueue; ) which is consisted of ten elements. Then I used measuresQueue.size() function. When I did the printf of the previous function it prints me the number four not ten. Can someone help me with this problem.



Here is my code:



In for loop I have entered my elements of the list:



for (filtertime_t=0; filtertime_t<=1.8; filtertime_t=filtertime_t+0.2) {



pssMeasure *mes = measureReceived(filtertime_t,y,mes_vect,mes_cov);

y++;



process_th->critical_section->writeMeasures(mes);



}

Here it is the measureReceived function description:

pssMeasure * measureReceived(double timeStamp,int j,double array[3][10], double array_cov[3]) {





pssMeasure *mes = new pssMeasure();





mes->track_id =7;

mes->timeStamp =timeStamp;



for (int i=0; i<3; i++)

{

mes->z_t[i]=array[i][j];



}





for(int i = 0; i < 3; i++) {



for(int k = 0; k < 3; k++)

mes->cov_z[i][k] = 0.0;



mes->cov_z[i][i] = array_cov[i];





}

return mes;

}

After creating mes I store them using the function writeMeasures:



void CPSSCriticalSection::writeMeasures(pssMeasure* pss_mes) {



measuresQueue.push_back(pss_mes);}



In order to check that my all elements are stored in the measuresQueue list I have used this after the measuresQueue.push_back(pss_mes);



cout << "hello1" << endl

printf("%f %f %f %f \n", pss_mes->timeStamp, pss_mes->z_t[0], pss_mes->z_t[1], pss_mes->z_t[2]);



Everything was fine until I wanted to see the size of my list measuresQueue with the: cout << "measuresQueue. size: " << measuresQueue.size() << '\n';



I always get the number 4 instead of ten. I don't know what is the reason?











Thank you,

M.













via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1pHsde9

View all the progranning help forums at:

http://ift.tt/1dP9txN

Sunday, April 27, 2014

WM_CLOSE in child window procedure problems

Newsgroup: comp.lang.c++

Subject: WM_CLOSE in child window procedure problems

From: ProDev7 <chenou7@...>

Date: Sun, 27 Apr 2014 09:35:08 -0500



hello everybody. I developped an mdi application everything is ok. but in the child window procedure if I handle WM_CLOSE:

if I maximize a child window then close it form its close box icon it'll be destroyed normally but its icon and its close box and minimize and maximize boxes are still there. if I don't handle WM_CLOSE everything is ok.

what's wrong with WM_CLOSE in child window procedure?



LRESULT callback ChildWinProc(HWND hWnd,UINT msg,WPARAM wParam,lParam)

{

//case WM_CLOSE:

// DestroyWindow(hWnd);

break;

default:

return DefMDIChildProc(hWnd,msg,wParam,lParam);

}

if I Uncomment the above lines the problem starts if I maximize the child window and then closing it













via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1h4H2yi

View all the progranning help forums at:

http://ift.tt/1dP9txN

shared_ptr problems

Newsgroup: comp.lang.c++

Subject: shared_ptr problems

From: cpisztest@...

Date: Thu, 24 Apr 2014 14:34:39 -0700 (PDT)



I wasn't around at design time, but I get to fix the problem...story of my life!



I know about boost::weak_ptr and would use that if the problem was limited to

classes A and B, but C has a public accessor that gives away shared_ptrs to As and I don't know what to do there.



I was thinking of trying to guarentee that Bs and Cs are only created by As and seeing if the compiler complained or not (unknown code base). If I can guarentee that Bs and Cs are only created by and used by As, then I can safely use weak_ptrs...I think. I could do that by hiding constructors of Bs and Cs making them private and friending them to A....I think.



Any thoughts/ideas?



The mess where nothing gets destroyed:



-----

#ifndef A_H

#define A_H



#include <boost/shared_ptr.hpp>

#include <boost/enable_shared_from_this.hpp>



#include <list>



class B;

class C;



class A : public boost::enable_shared_from_this<A>

{

public:



typedef boost::shared_ptr<A> SharedPtr;



A();

~A();



void Foo();



private:



std::list<B *> m_collectionOfBs;



void CleanupBs();

};



#endif

-----

#ifndef B_H

#define B_H



#include "A.h"

#include "C.h"



//--------

class B

{

public:



B(A::SharedPtr a);

~B();



private:



C m_c;

};



#endif

-----

#ifndef C_H

#define C_H



#include "A.h"



class C

{

public:



C(A::SharedPtr a);

~C();



A::SharedPtr GetA();



private:



A::SharedPtr m_a;

};



#endif

-----



#include "A.h"

#include "B.h"



A::A()

{

}



A::~A()

{

CleanupBs();

}



void A::Foo()

{

B * newbie = new B(shared_from_this());

m_collectionOfBs.push_back(newbie);

}



void A::CleanupBs()

{

std::list<B *>::iterator it = m_collectionOfBs.begin();



while (!m_collectionOfBs.empty() &&

it != m_collectionOfBs.end())

{

delete (*it);

it = m_collectionOfBs.erase(it);

}

}

-----

#include "B.h"



B::B(A::SharedPtr a)

:

m_c(a)

{

}



B::~B()

{

}

-----

#include "C.h"



C::C(A::SharedPtr a)

:

m_a(a)

{

}



C::~C()

{

}



A::SharedPtr C::GetA()

{

return m_a;

}

-----

#include "A.h"



int main()

{

A::SharedPtr a(new A());

a->Foo();



return 0;

}







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1h3uMht

View all the progranning help forums at:

http://ift.tt/1dP9txN

Monday, March 17, 2014

abstract class with virtual base class and non default constructor

Newsgroup: comp.lang.c++

Subject: abstract class with virtual base class and non default constructor

From: =?ISO-8859-1?Q?Marcel_M=FCller?= <news.5.maazl@...>

Date: Sat, 15 Mar 2014 18:26:54 +0100



Virtual base classes are always constructed by the most derived class.

So why need an abstract class a call to the constructor of it's virtual

base?



#include <stdio.h>



class V

{protected:

V(int i) { printf("V::V(%i)\n", i); }

};



class A : public virtual V

{protected:

A() : V(42) {} // <-- required to keep the compiler happy

virtual void PureFunc() = 0;

};



class D : public A

{public:

D(int i) : V(i) {}

protected:

void PureFunc() {}

};



int main()

{ D d(7);

}





From my understanding the constructor call V(42) could never be

executed, isn't it? A cannot be instantiated and any class inheriting

from A must initialize V::V(int) explicitly.





Marcel







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1nzip4T

View all the progranning help forums at:

http://ift.tt/1dP9txN

Thursday, March 13, 2014

Escape sequence and character set problem

Newsgroup: comp.lang.c++

Subject: Re: Escape sequence and character set problem

From: Victor Bazarov <v.bazarov@...>

Date: Thu, 13 Mar 2014 11:44:16 -0400



On 3/13/2014 11:39 AM, nvangogh wrote:

> What values does this literal represent? What type does it have?

> "Who goes with F\145rgus?\012"

>

> This is from C++ Primer exercise 2.7 (p41 of 5th ed)

>

> I cannot figure this out.

>

> F is a suffix for float that only makes sense to me if numeric value

> came before it. But it comes before an escape sequence. What does \145

> mean? Taken as a whole can you explain how this line is put together and

> how I can interpret it?



Inside a string literal, letter F has no special meaning. It's just a

letter. However, \145 is an escape sequence designating a special

character (most likely) with the value of decimal 145, which is actually

not possible in a basic character set limited to -127..127. So, most

likely it's substituted with char(255-145), some negative value, but

will yield the same thing however. Look up in the extended ASCII table

to see what your computer is likely to output. Or just write a small

program to output that literal. If we designate that character with the

asterisk (like in Scrabble) and the newline (the second escape sequence

is the line feed character) with the tilda, the literal becomes "Who

goes with F*rgus?~"



What it will do when you output it depends on the device, though.



V

--

I do not respond to top-posted replies, please don't ask







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1iGNqBO

View all the progranning help forums at:

http://ift.tt/1dP9txN

Which constructor?

Newsgroup: comp.lang.c++

Subject: Which constructor?

From: ram@...

Date: 13 Mar 2014 12:38:42 GMT



I tried to modify the __gnu_debug string after #include

<debug/string> to get this information, but it did not work,

because I am having problems to print something from inside

of it using ?::std::cerr?.



So, maybe someone here can tell me: What constructor or

method or whatever of the string class is called in the

case of each of the following two object definitions?



#include <string> /* ::std::string */



int main()

{ ::std::string s{ "alpha" };

::std::string t ={ "beta" }; }









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1cWJ8yn

View all the progranning help forums at:

http://ift.tt/1dP9txN

TALK.ORIGINS CENSORS THE TRUTH

Newsgroup: comp.lang.c++

Subject: Re: TALK.ORIGINS CENSORS THE TRUTH

From: Catpain Merca <catpainmerca@...>

Date: Wed, 12 Mar 2014 22:28:55 +0000



On 12/03/2014 22:07, I THRINAXODON wrote:



I've never seen the talk.origins moderator censor the truth. I have

seen him ban some nym-shifting dipshits. I, on the other hand have

snipped your entire rant. Not really censorship, as your original post

still stands, but completely disregarded without being read by me owing

to the stupidity of your subject header.



Catpain Merca









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1cWJ9lW

View all the progranning help forums at:

http://ift.tt/1dP9txN