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

Nested Boost::unordered_map with std::pair insertion help ..

Newsgroup: comp.lang.c++

Subject: Nested Boost::unordered_map with std::pair insertion help ..

From: Rahul Mathur <srivmuk@...>

Date: Thu, 20 Feb 2014 04:32:58 -0800 (PST)



All,



I have having Boost boost::unordered_map nested map calling boost::unordered_map which calls std::map finally.



The LHS (towards RHS) side key for first boost::unordered_map is 'int' type followed by next key being char buffer value of size 10, and key for std::map being again a char buffer value of size 10. So the boost::unordered_map has nested map internally.

I have to insert the char buffer of size 10 (value being either 'ORANGE' or ORD123 as test case) into nested std::pair as defined below. After inserting, I have to search or find the value from char buffer of size 10.



The code as compiled on Linux is -



----

#include <cstdio>

#include <cstdlib>

#include <iostream>

#include <boost/unordered_map.hpp>

#include <map>

#include <algorithm>

#include <string>



using namespace std;



#if 0

#pragma pack(push, 2)

struct BookKeeping {

int ABCD;

char Apple_ID [10];

char Apple_NAME[10];

int Price;

int Number;

};

#pragma pack(pop)

#endif



class Name { // buffer of size 10

char str[10];

public:

Name() {

strcpy(str, "");

}

Name(char *s) {

strcpy(str, s);

}

char *get() {

return str;

}

};



bool operator<(Name a, Name b)

{

return strcmp(a.get(), b.get()) < 0;

}



#pragma pack(push, 2)

struct BookKeeping {

int ABCD;

Name Apple_ID;

Name Apple_NAME;

int Price;

int Number;

};

#pragma pack(pop)



BookKeeping *_bkkping;



typedef boost::unordered_map< int, boost::unordered_map< Name, std::map< Name, int > > > _uordmap; // nested boost::unordered_map



class BkKping {

private:

_uordmap * uordmap;



typedef boost::unordered_map< int, boost::unordered_map< Name, std::map< Name, int > > >::iterator _itr_1;

typedef boost::unordered_map< Name, std::map< Name, int > >::iterator _itr_2;

typedef std::map< Name, int >::iterator _itr_3;



public:

BkKping () {

uordmap = new _uordmap ();

}

void Apple ( int abcd, const char * Apple_ID_, const char * Color_, int Price_ );

~BkKping () {

delete uordmap;

}



};



void BkKping::Apple ( int abcd, const char * Apple_ID_, const char * Color_, int Price_ ) {



uordmap->insert( std::pair< int, std::pair< Name, std::pair< Name, BookKeeping &> > > ( _bkkping->ABCD , _bkkping->Apple_ID, _bkkping->Apple_NAME, *_bkkping) ); // nested std::pair<> insertion

}



int main () {



int abcd;

const char * Apple_ID_;

const char * Color_;

int Price_;



BkKping book;

book.Apple( abcd, Apple_ID_, Color_, Price_);



}

-----



The error message is -



---

hello.cpp: In member function âvoid BkKping::Apple(int, const char*, const char*, int)â:

hello.cpp:76: error: no matching function for call to âstd::pair<int, std::pair<Name, std::pair<Name, BookKeeping&> > >::pair(int&, Name&, Name&, BookKeeping&)â

/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_pair.h:83: note: candidates are: std::pair<_T1, _T2>::pair(const _T1&, const _T2&) [with _T1 = int, _T2 = std::pair<Name, std::pair<Name, BookKeeping&> >]

/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_pair.h:79: note: std::pair<_T1, _T2>::pair() [with _T1 = int, _T2 = std::pair<Name, std::pair<Name, BookKeeping&> >]

/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_pair.h:68: note: std::pair<int, std::pair<Name, std::pair<Name, BookKeeping&> > >::pair(const std::pair<int, std::pair<Name, std::pair<Name, BookKeeping&> > >&)

--



I have created a class buffer to read size 10.



Please help.



P.S: No issue with Boost compilation, simply looking for proper semantic call for nested std::pair<>.







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

View all the progranning help forums at:

http://ift.tt/1dP9txN

Wednesday, February 19, 2014

Iterator pair as a function argument?

Newsgroup: comp.lang.c++

Subject: Iterator pair as a function argument?

From: nvangogh <nvangogh@...>

Date: Wed, 19 Feb 2014 20:22:47 +0000



Suppose I have a vector<int> values. Now the pair values.begin() and

values.end() will cover the range of the vector.



I am writing a simple function that takes the pair of iterators as

arguments along with an int value. The function then returns a bool to

indicate if the int value is found in the vector.



The first problem I have is to question if it is possible to pass

iterators as distinct arguments to a function? I would have thought that

the only way to accomplish this would be to pass the vector as a

reference, from there the function can use the iterators to do it's work.



I was thinking the correct definition would be



bool find_value (vector<int>&, int);



Or is there a way to pass an iterator pair as function arguments which I

have missed?







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

View all the progranning help forums at:

http://ift.tt/1dP9txN