Thursday, February 27, 2014

calling placement new for elements of a deque

Newsgroup: comp.lang.c++

Subject: calling placement new for elements of a deque

From: hbdevelop1@...

Date: Wed, 26 Feb 2014 21:50:29 -0800 (PST)



Hello

For optimisation reasons, I am re-using not used objects in my deque for new objects.

I am doing that this way :

void Score::Add(const char *str, Coordinates &sp)

{

for(deque<Text>::iterator it=scores.begin();it!=scores.end(); ++it)

{

if(it->notUsed==1)

{

it->Reset(str,sp);

return;

}

}



scores.push_back(Text(str,sp));

}



I thought it would be more convenient to call the placement new on the notUsed object instead of Reset.

How can I do this ?

How can I get the address of the not used object so I can use it in the new placement operator?





Thank you in advance







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

View all the progranning help forums at:

http://ift.tt/1dP9txN

How to download Microsoft Visuail c++ software

Newsgroup: comp.lang.c++

Subject: How to download Microsoft Visuail c++ software

From: 893756098a@...

Date: Tue, 25 Feb 2014 20:22:02 -0800 (PST)



Recently,our class had studied Microsoft Visuail c++.So I want to practice after school,but I can't install this.I would appreciate it if someone could do me a favour!







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

View all the progranning help forums at:

http://ift.tt/1dP9txN

Sunday, February 23, 2014

hw to get started

Newsgroup: comp.lang.c++

Subject: hw to get started

From: erson212 <erson212@...>

Date: Sun, 23 Feb 2014 01:20:06 -0800 (PST)



Please can some 1 tell me hw to get started with c++, first tin to du







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

View all the progranning help forums at:

http://ift.tt/1dP9txN

shared_ptr and unique_ptr related question

Newsgroup: comp.lang.c++

Subject: shared_ptr and unique_ptr related question

From: somenath <somenathpal@...>

Date: Fri, 21 Feb 2014 17:28:19 -0800 (PST)



To get some understanding of shared_ptr and unique_ptr I wrote the following naive implementation of linked list.



#include<memory>

using namespace std;



template <class T>

class List {

private:

class ListItem {

public:

ListItem( T Val );

shared_ptr <ListItem > Next;

T Data;



};



shared_ptr< ListItem >Head;



public:

int CreateNode();

List() {

Head.reset();

}

void PushBack(T Val);

void Dump();

};





template<class T>

List<T>::ListItem::ListItem( T Val):Data(Val) {

Next.reset();





}

template<class T>

void List<T>::PushBack( T val)

{

unique_ptr<ListItem > NewItem (new ListItem(val));

if (!Head ) {

Head = move(NewItem);

}

else {

shared_ptr<ListItem> Curr(Head);

shared_ptr<ListItem> Prev(Head);

while( (Curr) ) {

Prev = Curr;

Curr = Curr->Next;

}

Prev->Next = move(NewItem);

}

}



template<class T>

void List<T>::Dump() {

shared_ptr<ListItem > Curr(Head);

while ( Curr) {

cout<<"Val = "<<Curr->Data<<endl;;

Curr = Curr->Next;

}

}



But I am not very clear of the correct uses of shared_ptr and auto_ptr yet. Could you please comment on the uses of smart pointers in the context of my linked list code. According to my understanding where I do not need to assign smart pointers to other one I use unique_ptr . Is this understanding correct?



Also I am not able to get convinced the benefit of shared_ptr and unique_ptr in the context of my code. I could have used even raw pointers to implement the same without losing much benefit . Is it not the case here?



I can use the above code as



int main(int argc,char *argv[] )

{

unique_ptr< List <int> > ilst (new List<int>());



ilst->PushBack(5);

ilst->PushBack(15);

ilst->PushBack(25);

ilst->Dump();



return 0;

}



Is the benefit of using smart pointers is, ilst need to be freed manually?



Please point me to some real code where smart pointers has been heavily used.



--

Somenath







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

View all the progranning help forums at:

http://ift.tt/1dP9txN

Friday, February 21, 2014

implicit passing by reference

Newsgroup: comp.lang.c++

Subject: implicit passing by reference

From: jerry.jeremiah@...

Date: Thu, 20 Feb 2014 20:45:27 -0800 (PST)



In this topic



http://ift.tt/1fobfKU



The person that answers it says:



You have to remember that objects are sent to functions 'by reference'.



But the object being passed contains only one int member and the function the object is being passed to clearly takes it's parameter by value and stores it in a member value.



Do objects really always pass by reference regardless of what the parameter list says? And, if so, why would it do that? I would usderstand if the function took its parameter explicitly by reference...



Thanks for clearing up mu confusion.



Jerry







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

View all the progranning help forums at:

http://ift.tt/1dP9txN

Thursday, February 20, 2014

Working with Large Values (double)

Newsgroup: comp.lang.c++

Subject: Working with Large Values (double)

From: mrc2323@...

Date: Thu, 20 Feb 2014 17:25:50 -0700



How can I express a large value as a double? (e.g. 1000000.3)

Whereas this compiles and executes, when I try to convert it to a

string value it converts as a scientific string (e.g. "1e+006", not

"1000000.3"). I want to process all the characters of the value of the

data as a std::string.

Or is there a way to convert the double to assure it's not expressed

in scientific notation? TIA



---

This email is free from viruses and malware because avast! Antivirus protection is active.

http://www.avast.com









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

View all the progranning help forums at:

http://ift.tt/1dP9txN

OT: Problem building libc++

Newsgroup: comp.lang.c++

Subject: OT: Problem building libc++

From: woodbrian77@...

Date: Thu, 20 Feb 2014 15:00:24 -0800 (PST)





I was following these instructions



http://ift.tt/UxFMKX



but have a problem when I get to building libc++.



Linking CXX shared library libc++.so

/usr/bin/ld: cannot find -lsupc++





I tried:



find / -type f -name "*supc++*" -print



but it didn't find any files that matched that.



I searched on https://duckduckgo.com and bing for

some ideas, but haven't found the answer.



What do you suggest? Thanks in advance.



Brian

Ebenezer Enterprises - In G-d we trust.

http://webEbenezer.net







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

View all the progranning help forums at:

http://ift.tt/1dP9txN