Tuesday, July 30, 2013

The C++ Programming Language, 4th Ed.

Newsgroup: comp.lang.c++

Subject: The C++ Programming Language, 4th Ed.

From: Michael Mueller <mighty.mueller@...>

Date: Tue, 30 Jul 2013 00:30:20 +0200



EPUB: http://www.embedupload.com/?d=9JVNYEGAIG (159MB!)

PDF: http://www.embedupload.com/?d=7BEDFXUSAL (18,7MB)







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?53801-The-C-Programming-Language-4th-Ed&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Sunday, July 28, 2013

error in 41st line tell me whats the mistake i did everything right

Newsgroup: comp.lang.c++

Subject: error in 41st line tell me whats the mistake i did everything right

From: wajihahmed29@...

Date: Sun, 28 Jul 2013 02:43:46 -0700 (PDT)



Error 41: Declaration syntax error in function main()





#include <iostream.h>

#include <conio.h>



float sum(float,float);

float sub(float,float);

float mult(float,float);

float div(float,float);

float mod(float,float);



void main()

{

clrscr();

int a,b;

char calculator;

cout <<"Press (P) for sum, Press (S) for sub,Press (M) for mult,Press (D) for div,Press (N) for mod";

cin >>calculator;

switch(calculator)

{

case 'P':

cout <<"Sum (a,b)";

cin >>a >>b;



case 'S':

cout <<"Sub (a,b)";

cin >>a >>b;



case 'M':

cout <<"Mult (a,b)";

cin >>a >>b;



case 'D':

cout <<"Div (a,b)";

cin >>a >>b;



case 'N':

cout <<"Mod (a,b)";

cin >>a >>b;

}

float sum(float a,float b)

{

return a+b;

}

float sub(float a,float b)

{

return a-b;

}

float mult(float a,float b)

{

return a*b;

}

float div(float a,float b)

{

return a/b;

}

float mod(float a,float b)

{

return a%b;

}

getch();

}







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?52756-error-in-41st-line-tell-me-whats-the-mistake-i-did-everything-right&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

cast multimap values

Newsgroup: comp.lang.c++

Subject: cast multimap values

From: scrat_here@...

Date: Sat, 27 Jul 2013 23:34:32 -0700 (PDT)



Hi

How to solve the error:



error: invalid cast from type ?std::pair<const std::basic_string<char>, std::vector<Procedure*> >? to type ?const char*?



Many thanks







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?52732-cast-multimap-values&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

static const int problem

Newsgroup: comp.lang.c++

Subject: Re: static const int problem

From: cathode26@...

Date: Sat, 27 Jul 2013 22:29:53 -0700 (PDT)



On Tuesday, May 15, 2007 6:17:01 AM UTC-5, mati wrote:

> Hi

>

> The following code works:

>

> #include <vector>

> class C {

> private:

> static const int m_static = 2;

> public:

> void f(const std::vector<int>& v)

> {

> int a = m_static;

> std::vector<int> stripped(v.begin()+a, v.end());

> //std::vector<int> s2(v.begin()+m_static,v.end());

> }

> };

> int main()

> {

> C c;

> std::vector<int> pv;

> int i;

> pv.push_back(i);

> pv.push_back(i);

> pv.push_back(i);

> c.f(pv);

> }

>

>

> But when I erase the comment in the void f(...), then compiler gives an

> error:

>

> g++ -ansi -Wall -o test test.cpp

> /tmp/cckLnGUY.o: In function `C::f(std::vector<int, std::allocator<int>

> > const&)':

> test.cpp:(.text._ZN1C1fERKSt6vectorIiSaIiEE[C::f(std::vector<int,

> std::allocator<int> > const&)]+0xdb): undefined reference to `C::m_static'

> collect2: ld returned 1 exit status

> make: *** [test] Error 1

>

> g++ --version

> g++ (GCC) 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)

>

>

> Can anybody tell me what I'm doing wrong?



So I tried your code in Visual Studio and it works fine, but if you use http://codepad.org/ your code does not compile. It is true, this is a declaration and not a definition. You need to define it like so.



#include <vector>



class C {

private:

static const int m_static = 2;

public:

void f(const std::vector<int>& v);



};



const int C::m_static;



void C::f(const std::vector<int>& v)

{

int a = m_static;

std::vector<int> stripped(v.begin()+a, v.end());

std::vector<int> s2(v.begin()+m_static,v.end());

}



int main()

{

C c;

std::vector<int> pv;

int i;

pv.push_back(i);

pv.push_back(i);

pv.push_back(i);

c.f(pv);

}







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?52722-static-const-int-problem&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

std::istream::tellg vs eofbit flag

Newsgroup: comp.lang.c++

Subject: std::istream::tellg vs eofbit flag

From: mathieu <mathieu.malaterre@...>

Date: Thu, 25 Jul 2013 09:41:12 -0700 (PDT)



Hi,



I'd like to check if my understanding of the standard is correct. Is the following program supposed to work ?



$ cat file.cxx

#include <cassert>

#include <fstream>

#include <sstream>



int main ()

{

std::ifstream ifs (__FILE__, std::ios::binary);

std::stringstream ss;



assert (0 == ifs.tellg ());



ifs >> ss.rdbuf ();



assert (ifs.eofbit == ifs.rdstate ());

assert (ifs.eof());

assert (-1 != ifs.tellg ()); // works with g++ 4.4



return 0;

}



I am getting different results using either g++ 4.4 or g++ 4.7.



Thanks.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?50703-std-istream-tellg-vs-eofbit-flag&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Thursday, July 25, 2013

Request for build feedback

Newsgroup: comp.lang.c++

Subject: Request for build feedback

From: woodbrian77@...

Date: Thu, 25 Jul 2013 16:40:12 -0700 (PDT)





I have access to Linux machines and a couple of Windows 7

machines. I'd like to know how this software



http://webEbenezer.net/misc/direct.tar.bz2 (*)



builds, especially on systems that I don't have like

Solaris, HP, Windows 8, etc.



A C++ compiler with support for the 2011 standard is

needed. VS 11 might work. VS 12 does here.



There's a Readme file in the archive which tells about

the makefiles in the archive. There's a separate

makefile for Windows. On Windows a library and one

executable are built. On Linux the same library and

executable are built plus a second executable is built.



The file to download is 21,059 bytes at this time so

downloading it shouldn't take long. On my Linux system

the library and two programs build in 9 seconds. If

everything goes well, the downloading, tar xf direct.tar.bz2,

and building should take less than a minute.



I'd like to know if it does or doesn't build on your

system. If you prefer to send an email, that would be

fine.



Feel free to keep the software if you like. However, two

of the files in the archive are from another developer

and should only be used in conjunction with the rest of

the software. Those files are quicklz.h and quicklz.cc.

See http://quicklz.com for more info.



Thank you in advance.



Brian

Ebenezer Enterprises - Learning how to walk on economic water.

http://webEbenezer.net



(*) More info here

http://webEbenezer.net/build_integration.html







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?51075-Request-for-build-feedback&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Programming in C++ for both 32-bit and 64-bit

Newsgroup: comp.lang.c++

Subject: Re: Programming in C++ for both 32-bit and 64-bit

From: Paavo Helde <myfirstname@...>

Date: Thu, 25 Jul 2013 15:22:06 -0500



"Qu0ll" <Qu0llSixFour@...> wrote in

news:ZZKdnYzsgvR6mGzMnZ2dnUVZ_g6dnZ2d@...



> What are the main issues when developing software with C++ which needs

> to support both 32-bit and 64-bit operating systems?

>

> Is C++ code portable across these different architectures?



Sure one can write portable code for those architectures as well as for a

lot of others.



> Any special "gotchas" in writing portable C++ code of this nature?



You might want to avoid long datatype, it has different size on different

64-bit platforms. Use int64_t, uint64_t instead if your algorithm

requires more than 32 bits.



Beware that size_t will be different in 32-bit and 64-bit architectures.



When converting pointers into integers or vice versa (this is not ultra-

portable anyway) make sure that the integer has matching size.



Use std::string::size_type for storing string indices. Especially the

std::string::npos constant is very 64-bit on 64-bit platforms and

comparing it with any 32-bit index always yields false.



Not directly related to portability, but make sure time_t and file

offsets are always 64-bit even in 32-bit compilations.



Use typedefs for things which might change in the future, so you can

change a single typedef when this happens. It is also a good idea to use

short typedefs for long typenames as std::string::size_type.



hth

Paavo









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?50961-Programming-in-C-for-both-32-bit-and-64-bit&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Wednesday, July 24, 2013

What Am I Missing?

Newsgroup: comp.lang.c++

Subject: Re: What Am I Missing?

From: Ian Collins <ian-news@...>

Date: Thu, 25 Jul 2013 11:21:24 +1200



Mike Copeland wrote:

> I have a lot of C-based code that I'm (slowly) converting to C++,

> STL, and what I hope to be code that's easier to manage. I'd also like

> to gain performance increases and reduced code - but I'm not really

> seeing the latter improvements. 8<{{

> As I think about it, there appear to be some trade-offs with either

> type of coding:

> 1. C-based strings require fixed (max) size declarations and runtime

> code to scan these character strings to determine size - so that

> operations can be made on them. There's overhead in both object file

> size and execution processing to deal with such data.

> 2. STL strings, on the other hand, are instantiated as object pointers

> that require runtime memory allocation(s), which might be done over and

> over as the data values change throughout execution. (That is, checks

> must determine if currently allocated data sizes are adequate, and

> deallocation/reallocation done if not. This might require substantial

> runtime logic to do for each and every string object.)



C++ strings (STL isn't an appropriate prefix) can also have a fixed size

reservation, just as C strings would have to be dynamically managed if

the initial size wasn't known. So there's no additional cost with C++

strings, but considerable savings in programmer effort!



> Thus, program object sizes should probably be smaller for C++

> programs, but C-based programs should generally be larger than

> corresponding C++ executables. I'm not seeing this phenomenon at all -

> in fact, the opposite seems true.



Define size. Fully optimised and stripped binary? Debug binary?



> I don't know if C++ programs execute any faster than C programs (I

> suspect they don't), and I don't know if any of my applications would

> expose this fact, either way.

> I do know that my C++ programs are invariably larger than their C-

> based versions.

> If there's no other factor in what I'm seeing, I guess the only real

> benefit to C++ and STL is ease of coding, debugging and maintenance.

> <sigh> Any thoughts?



Those are big benefits.



--

Ian Collins







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?50436-What-Am-I-Missing&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

An Easier Way?

Newsgroup: comp.lang.c++

Subject: An Easier Way?

From: mrc2323@...

Date: Tue, 23 Jul 2013 16:07:59 -0700



The code below seems clumsy; I'm only replacing some C-based

"sprintf" logic here. Is there a simpler and slicker way to do this

sort of thing? TIA



time_t nEstTime = 0; // some value...

ostringstream ossw;

string estTimeStr;

ossw.clear(), ossw << setw(6) << nEstTime, estTimeStr = ossw.str();







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?49518-An-Easier-Way&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Thursday, July 18, 2013

when V-pointer becomes NULL

Newsgroup: comp.lang.c++

Subject: when V-pointer becomes NULL

From: Jaydeep Chovatia <chovatia.jaydeep@...>

Date: Thu, 18 Jul 2013 12:33:05 -0700 (PDT)



Hi,



In my application object's v-pointer becomes NULL under load. I have Base class - Derive class type of hierarchy with pure virtual functions and my constructor/destructor are inline. I have checked Derive class member variables and they are fine (i.e. obj was not deleted anytime) only v-ptr is NULL.



Can somebody please point me in which all situations v-pointer become NULL?



I've already checked following links and none of them help:

http://stackoverflow.com/questions/3966039/why-does-my-c-object-loses-its-vptr

http://stackoverflow.com/questions/992786/vftptr-is-null





-jaydeep







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?45620-when-V-pointer-becomes-NULL&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

gcc and glib - relation

Newsgroup: comp.lang.c++

Subject: gcc and glib - relation

From: arun Coder <codepriest.1981@...>

Date: Thu, 18 Jul 2013 08:50:30 -0700 (PDT)



Is there a relation between the version of gcc used to compile our application and the version of glibc used when running the application.



Example if i build my application with a old version of gcc (2.3.1), while building my application the version of glibc on that server is 1.7.5.



But i run my application on a new server which is running a newer version of glibc 2.3



Will my application be able to use the full potential and all the features of the new glibc. Or will my application be able to use only those features of libc which were available while building my application?



Thanks,

Da







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?45460-gcc-and-glib-relation&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Tuesday, July 16, 2013

Faster than std::vector and std::list!

Newsgroup: comp.lang.c++

Subject: Faster than std::vector and std::list!

From: Leigh Johnston <leigh@...>

Date: Mon, 15 Jul 2013 22:21:40 +0100



Just a reminder that the best fight scene of all time is still the one

from "They Live": http://www.youtube.com/watch?v=c9rrgJXfLns







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?42547-Faster-than-std-vector-and-std-list!&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Sunday, July 14, 2013

Using istream in as a function parameter

Newsgroup: comp.lang.c++

Subject: Using istream in as a function parameter

From: "Steph W." <swilks06@...>

Date: Sun, 14 Jul 2013 14:44:33 -0700 (PDT)



Hello,



I had a quick question about using istream/cin as a function parameter. I'm working on a homework problem that is requiring me to create a recursive function called Max that returns the max value of a sequence of numbers that is entered in by the user. We are not allowed to use any type of data structure and thats why I chose to use istream/cin. Here is what I have so far:





#include <iostream>

#include <istream>



using namespace std;



int MAX(istream x);



int main()

{

int number;

char option;



cout << "This program will print out the maxium value that the user inputs.";

do

{

cout <<"Enter in values to find the maxium number. Enter in -1 to stop: ";

cout << MAX(cin) << endl;

cout <<"Would you like to run the program again? (Y/N): ";

cin >> option;

}while(toupper(option) =='Y');



return 0;

}



int MAX(istream x)

{

int largest =0;

if (x <= 0)

return largest;

if ((x % 2 == 0) && (largest < x)) //IntelliSense: no operator "%" matches these operands



{

largest = x; // IntelliSense: no suitable conversion function from "std::istream" to "int" exists



return MAX(x);

}

else

MAX(x);

return return largest;

}









Thank you in advance for any advice.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?42252-Using-istream-in-as-a-function-parameter&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Is binding non-const references to temporaries the sole key feature of rvalue references?

Newsgroup: comp.lang.c++

Subject: Is binding non-const references to temporaries the sole key feature of rvalue references?

From: "K. Frank" <kfrank29.c@...>

Date: Sun, 14 Jul 2013 08:22:16 -0700 (PDT)



Hello Group!



Is the ability to bind a non-const reference to a

temporary the only important feature / benefit of

rvalue references?



Please note, I am not asking what it is that rvalue

references let you do; I am asking what specific

capability of rvalue references lets you do those

things.



Asked another way, if we were to permit regular

non-const references to bind to temporaries (I'm not

saying we should.), would there remain any need to

introduce rvalue references into the language?



Basic illustration:



// int& nr = 1; // illegal: non-const reference to temporary

const int& cr = 2; // const reference okay

int&& rr = 3; // non-const rvalue reference okay





Thanks for any insight.





K. Frank







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?42096-Is-binding-non-const-references-to-temporaries-the-sole-key-feature-of-rvalue-references&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

The C++ Language 4th edition - Subclassing vector for range checking.

Newsgroup: comp.lang.c++

Subject: The C++ Language 4th edition - Subclassing vector for range checking.

From: mrileyoscmp@...

Date: Sat, 13 Jul 2013 18:26:45 -0700 (PDT)



I was under the impression that it was generally a bad idea to subclass vector because the destructor is not virtual because if someone referenced an object of your class with a pointer and then deleted it with the base, the operation is undefined.



In The C++ Programing Language 4.4.1.2 Stroustrup says "... I often use a simple range-checking adaption of vector:"



template<typename T>

class Vec : public std::vector<T> {

public:

using vector<T>::vector;



T & operator[](int i)

{return vector<T>::at(i);}



const T & operator[](int i) const

{return vector<T>::at(i);}

};



I thought this was some what dangerous because if an user of the class (Maybe not the person who wrote it) writes:

Vector<T> * vectorObject = new Vec<int>(100);

delete vectorObject;



Results in undefined behavior.



Did something change in C++11? Is there some common idiom where people create classes that must be on the stack or they should know not to delete the base?



I ask because this seems like it would create error prone code.



















via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?41835-The-C-Language-4th-edition-Subclassing-vector-for-range-checking&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Saturday, July 13, 2013

Sorting vector Multiple Ways

Newsgroup: comp.lang.c++

Subject: Sorting vector Multiple Ways

From: mrc2323@...

Date: Sat, 13 Jul 2013 14:35:45 -0700



Is there a way to sort the vector below in more than one way? The

code below works, but I find a need to sort and search on a second field

(eName). Is this possible? TIA



class MyEvents

{

public:

bool bIsScored;

int eSeq;

double eDist;

string evKey;

string eRoot;

string eEvent;

string eDate;

string eYear;

string eCode;

string eName;

bool operator<(MyEvents rhs) { return evKey < rhs.evKey; }

};

vector<MyEvents> evVect;

vector<MyEvents>::const_iterator evIter;







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?41753-Sorting-vector-Multiple-Ways&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

why assigning to mismatch type in template still works.

Newsgroup: comp.lang.c++

Subject: why assigning to mismatch type in template still works.

From: wy <warmyouth@...>

Date: Sat, 13 Jul 2013 12:24:35 +0800



Here is the code.



/* main.cpp */

#include <iostream>



template <typename T>

class test

{

public:

test(T tmp)

: t(tmp){

}



T get(){

return t;

}

void set(T tmp){

t = tmp;

}



T t;

};



int main(void){

char buf[] = "hello, world";

test<std::string> instance(buf);

std::cout << instance.get() << std::endl;

instance.set(buf + 7);

std::cout << instance.get() << std::endl;

}

/* end of main.cpp */



The output is

$ ./a.out

hello, world

world



But why will it still work when assigning a char pointer to "instance",

which accepts std::string only?

Is there any unusual relationship between std::string and char?

Or have I misunderstood the property of template?

Thanks for your help!









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?41447-why-assigning-to-mismatch-type-in-template-still-works&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Friday, July 12, 2013

Negative zero.

Newsgroup: comp.lang.c++

Subject: Negative zero.

From: Leigh Johnston <leigh@...>

Date: Fri, 12 Jul 2013 20:40:16 +0100



There is no such thing as negative zero. IEEE 754 got it wrong.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?41198-Negative-zero&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Classify clock() for variables of type clock_t

Newsgroup: comp.lang.c++

Subject: Classify clock() for variables of type clock_t

From: clusardi2k@...

Date: Fri, 12 Jul 2013 06:12:36 -0700 (PDT)



Hello,



I was recently notified that I can not use "clock()" even though it works fairly well on my computer!



Question: Based on this information, how can I identify other functions that I am not allowed to use?



Thanks,







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?40988-Classify-clock()-for-variables-of-type-clock_t&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Learning C++

Newsgroup: comp.lang.c++

Subject: Learning C++

From: Arnuld <sunrise@...>

Date: 12 Jul 2013 03:59:54 GMT



I have Stroustrup 3/e and TiCPP by Bruce Eckel, both 2002 editions.

Recently Stroustrup 4/e came out and still unavailable in India. I read 4/

e DRAFT chapters from Stroustrup's site and they seem to be totally

different from 3/e. I am financially very tight hence can not import 4/e

from outside. I gotta read what I can get in India.



Josuttis's book C++ standard Library 2nd edition updated for C++11

(http://www.cppstdlib.com/) and it is is available in India.



Do you guys recommend just reading these old Stroustrup 3/e and TiCPP and

use Josuttis as reference for everything ? (I am working in C from last

4.5 years and familiar with C++ but never got chance to work full-fledged

with it while I was doing job. Now I am jobless and C++ has always been

on my list and hence I want to go guns-blazing)



----







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?40746-Learning-C&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Thursday, July 11, 2013

How come this is undefined behavior?

Newsgroup: comp.lang.c++

Subject: How come this is undefined behavior?

From: Peter <pilarp@...>

Date: Thu, 11 Jul 2013 13:35:38 -0700 (PDT)



Section 1.9 ("Program execution") of C++11 standard introduces the following example of undefined behaviour:



for function declared as



void f(int, int);



the call:



f(i = -1, i = -1);



yields undefined behaviour.



How come? Of course I know the order in which arguments of f are evaluated is unspecified, so result of f(i, i++) would indeed be undefined, but what's wrong with f(i = -1, i = -1)? Why should the order matter here? f doesn't get called until both arguments are evaluated and both assignment expressions are independent, so what difference does it make if first and then second gets evaluated or the other way round since both evaluate to -1 anyway?









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?40485-How-come-this-is-undefined-behavior&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Is There a C++ Timer Like the java.util.Timer

Newsgroup: comp.lang.c++

Subject: Is There a C++ Timer Like the java.util.Timer

From: clusardi2k@...

Date: Thu, 11 Jul 2013 05:37:19 -0700 (PDT)



In java, they have a class where you can create a timer which will repeatedly call a routine after a time period. Is there something like this in C++ Visual Studio 2010?



Thanks,





P.S.: Java Reference:

http://www.java2s.com/Code/Java/Development-Class/UsejavautilTimertoscheduleatasktoexecuteonce5secon dshavepassed.htm







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?40082-Is-There-a-C-Timer-Like-the-java-util-Timer&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Tuesday, July 9, 2013

Exception caught inside a constructor

Newsgroup: comp.lang.c++

Subject: Exception caught inside a constructor

From: Jarek Blakarz <jumianek@...>

Date: Tue, 9 Jul 2013 07:33:38 -0700 (PDT)



Hi



The following program throws an exception while allocating "A" object.

Allocation fails. An exception is caught inside "C" constructor.

"C" destructor releases memory for both objects. Segmentation fault

occurs while releasing memory for object "A" since the memory has actually not

been allocated for that object.



Please help me to modify the program to work correctly. I want all exceptions

to be caught inside a "C" constructor and no memory leak should happen.



I am aware that this problem may be solved by wrapping ptrA and ptrB in a smart

pointers but I am not interested in this solution.



Thanks for help.



#include <iostream>



using namespace std;



struct A {

A(void)

{

cout << "A" << endl;

}



~A(void)

{

cout << "~A" << endl;

}



void* operator new(size_t size)

{

cout << "A new" << endl;

throw 10; // allocation fails

return ::operator new(size);

}

};



struct B {

B(void)

{

cout << "B" << endl;

}



~B(void)

{

cout << "~B" << endl;

}

};



struct C {

B *ptrB;

A *ptrA;



C(void)

{

cout << "C" << endl;

try {

ptrB = new B;

} catch(...) {

cout << "new B - exception" << endl;

}

try {

ptrA = new A;

} catch(...) {

cout << "new A - exception" << endl;

}

}



~C(void) {

cout << "~C" << endl;

delete ptrB;

delete ptrA;

}

};



int main(void)

{

try {

C c;

} catch(...) {

cout << "main exception handler" << endl;

}

}







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?38600-Exception-caught-inside-a-constructor&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

The start of a C/C++ adventure...

Newsgroup: comp.lang.c++

Subject: The start of a C/C++ adventure...

From: "Qu0ll" <Qu0llSixFour@...>

Date: Tue, 9 Jul 2013 20:36:26 +1000



I have been programming (mainly) in Java for a number of years but am now

about to embark on an adventure in C/C++.



I found that Java was very suitable for most of the applications I have been

developing and, contrary to popular belief, very fast in most circumstances.

For my server-side work I will still use Java as the principle language of

choice on the basis of the language itself, the productivity of tightly

integrated IDEs, the plethora of build/test tools, the vast standard library

of classes and also the even "vaster" array of 3rd-party libraries that are

available. But I have found one usage scenario where Java is just not going

to cut it...



That is, the UI.



I will almost certainly not be using Java for UI programming (anymore). The

once standard Java GUI toolkit (Swing) has now been deprecated by Oracle

(Java's custodian) and replaced by a hardware-accelerated toolkit known as

JavaFX. Don't get me wrong, JavaFX is a truly excellent product with many

very nice features but its one major flaw is that (as yet at least) it does

not run on "modern" platforms such as mobiles and tablets (e.g. iPhone, iPad

& Android). To me, this means this toolkit is not suitable and probably has

a limited lifespan (unless Oracle commits to an official release for iOS,

Android and Windows RT in the very near future).



So, what do I choose then? Well, after researching the various options I

have decided that the *only* language/platform that seems to be truly

portable (in one way or another) is C/C++ and so I am going to devote a

large amount of effort and resources into learning this language(s) and the

associated ecosystem.



Given that I am about to embark on a *major* project and that much of my

time will now be devoted to getting up to speed in this new language which I

really enter at a "novice" level, I would really appreciate people taking

the time to answer some questions I have at this point. Please bear in mind

that I am a very experienced developer in many other languages, tools, IDEs

etc. and all other aspects of the software development life cycle but do

lack any real practical experience with C++.



First up, I can see that a new standard C++11 has recently been ratified.

OK, so I don't really want to learn anything else but is this possible? I

want to target *all* the main platforms and OSes such as Windows, MacOS,

Linux and *especially* iOS and Android with Windows RT as a bonus. My first

question therefore is this:



1. Is there enough support in terms of compilers and tools to focus

exclusively on C++11 on *all* these platforms or will I just have to suck it

up and learn the older versions of the language because they are the only

ones that run on some of these platforms?



Armed with the answer to question (1), I would like to then look at the best

compilers and tools. For Windows the general buzz is that Visual C++ (and I

would go straight to VS 2012 or even 2013) seems the best environment and

compiler. For Linux it looks like I would have to use GCC and perhaps

Eclipse. For MacOS and iOS it looks like clang through XCode but I am not

sure what is available on Android.



2. What are the best compilers/IDEs and tools for the various platforms and

is it possible to reuse some of the compilers or tools across multiple

platforms? For example, I know Eclipse runs on most platforms but I am not

sure of the quality of the CDT tools it embodies.



This leads me to the next obvious question:



3. Is C++ (especially C++11) *really* portable across all or some of these

platforms or is it necessary to write a great deal of platform-specific

code to develop apps that run on all of them?



Depending on the answer to (3), a further question may be:



4. Is it better to rely simply on C rather C++ to best achieve portability?

If yes, how would I "get" similar functionality that is provided in

libraries written exclusively in C++?



My research suggests that the C and C++ languages themselves are quite

portable but the libraries and windowing toolkits etc. on each platform are

vastly different. This is OK, I am hoping to be able to compartmentalise as

much of the "core" functionality into portable C++ classes and then perhaps

just write native wrappers on each individual platform.



Right, at this point I should know which compilers/tools to use and

precisely which language so next question is to the availability of

cross-platform graphics toolkits. Again, my research suggests that Qt is

head and shoulders above the other offerings on the market but that may not

be correct in all cases. So, in this light, my next question is:



5. What are the best GUI toolkits for C/C++ available that support (at least

in part) true cross-platform development of GUI applications? Is there one

"stand-out" product?



Now I want to look at supporting libraries of more general functionality.

From my research again I see that Boost is used quite heavily and that C++

has a comprehensive standard library anyway. Obviously I have to learn the

latter but my next question is:



6. Is Boost a good bet for additional functionality and is it available on

all the platforms I have mentioned?



Next I want to investigate issues surrounding the build pipeline, in

particular build and CI tools. For Java I have used Ant, Maven and (lately)

Gradle but for C/C++ the common ones seem to be good-old "make" and a now

CMake so my next question is:



7. What are the best build tools for C/C++ development that support

cross-platform development, ideally being able to build native executables

for as many platforms as possible on one single platform?



Then there is the issue of unit testing. Obviously for Java the most common

tool is JUnit and I believe there is also a CPPUnit so my next question is:



8. What are the best unit testing tools, preferably ones that integrate well

with IDEs or tools in (2) and (7) and that provide such feedback as coverage

reports etc.?



That's pretty much the main set of questions I have for now but finally I

would just like to ask:



9. Is there any additional advice that could be offered to someone in my

position that may assist me in cutting through the noise and getting up to

highly-productive speed in C/C++ as soon as possible?



Thanks very much for any input you can provide!



--

And loving it,



-Qu0ll (Rare, not extinct)

_________________________________________________

Qu0llSixFour@...

[Replace the "SixFour" with numbers to email me]









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?38482-The-start-of-a-C-C-adventure&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Template function specialization once again (test a little, post a little)

Newsgroup: comp.lang.c++

Subject: Template function specialization once again (test a little, post a little)

From: Daniel <danielaparker@...>

Date: Mon, 8 Jul 2013 19:26:04 -0700 (PDT)



Special thanks to everyone who attempted to responded to my

original post, particularly Geoff and Gerhard.



This time I've hopefully posted code that better illustrates

my question. Basically the question is, does the output from

VC 10 for examples 1 and 2 below conform to expected output?



The context is a C++ template library that supports a default

serialization method for custom types, but allows the

library user to override it with something more sensible.



Example 1

=========



test.h

------



#ifndef TEST_HPP

#define TEST_HPP



#include <iostream>



namespace ns

{

template <class T>

void serialize(std::ostream& os, const T& A)

{

os << "null" << std::endl;

}



template <class T>

class A

{

public:

A(const T& A)

: A_(A)

{

}

void serialize(std::ostream& os) const

{

ns::serialize(os,A_);

}



T A_;

};

}

#endif



test1.h

-------



#ifndef TEST1_HPP

#define TEST1_HPP



void f();



#endif



test.cpp

--------



#include "test.h"

#include "test1.h"



int main()

{

ns::A<double> a(10.0);

a.serialize(std::cout);

f();

}





test1.cpp

---------



#include "test.h"



void f()

{

ns::A<double> b(10.0);

b.serialize(std::cout);

}



Visual Studio 10 gives the linker error



>test1.obj : error LNK2005: "void __cdecl ns::serialize etc etc



: fatal error LNK1169: one or more multiply defined symbols found



So, test.cpp and test1.cpp induce different instantiations of

the function serialize with the same arguments?



Example 2

=========



test.h

------



Same as above



test1.h

-------



#ifndef TEST1_HPP

#define TEST1_HPP



#include <iostream>



void f();



namespace ns

{

template <>

void serialize(std::ostream& os, const double& A)

{

os << A << std::endl;

}

}



#endif



test.cpp

--------



Same as above



test1.cpp

---------



#include "test.h"

#include "test1.h"



void f()

{

ns::A<double> b(10.0);

b.serialize(std::cout);

}



Visual Studio 10 still gives the linker error



test1.obj : error LNK2005: "void __cdecl ns::serialize<double> etc.

LNK1169: one or more multiply defined symbols found



Even with template <>, the linker thinks there are multiple

definitions of serialize per header inclusion?



Example 3

=========



As above, except



test1.h

-------



#ifndef TEST1_HPP

#define TEST1_HPP



#include <iostream>



namespace ns

{

template <> inline

void serialize(std::ostream& os, const double& A)

{

os << A << std::endl;

}

}



#endif



--------------------------------



This time with inline in the template definition

Visual Studio 10 links and gives the correct result.

But should inline be necessary?



Example 4

=========



As above, except



test1.h

-------



#ifndef TEST1_HPP

#define TEST1_HPP



#include <iostream>



namespace ns

{

template <>

void serialize(std::ostream& os, const double& A);

}

#endif



test1.cpp

---------



#include "test.h"

#include "test1.h"



void f()

{

ns::A<double> b(10.0);

b.serialize(std::cout);

}



namespace ns

{

template<>

void serialize(std::ostream& os, const double& A)

{

os << A << std::endl;

}

}

--------------------



Again Visual Studio 10 links and gives the correct result.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?38297-Template-function-specialization-once-again-(test-a-little-post-a-little)&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

About pointers and private membership

Newsgroup: comp.lang.c++

Subject: About pointers and private membership

From: joshipura@...

Date: Mon, 8 Jul 2013 10:34:42 -0700 (PDT)



I have a basic question.

I want to communicate a value v [2D array of characters] between two objects o1 and o2 of classes c1 and c2 respectively. Something like this:



c1's code calls

o2::method; //should return value v



My question is, if this value is defined as a private member of o2/c2, should not this address be invalid/illegal in the scope of o1?



Then, if I define the array as a member of o1/c1 and pass it by reference, should it not be invalid/illegal in the scope of o2?



If private members don't have any meaning outside the object, how do pointers ever pass?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?37992-About-pointers-and-private-membership&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Sunday, July 7, 2013

std::setw() Not Working?

Newsgroup: comp.lang.c++

Subject: std::setw() Not Working?

From: mrc2323@...

Date: Sun, 7 Jul 2013 11:10:48 -0700





The following code doesn't work as I understand it should.

Specifically, the "setw" takes effect for only the data which

immediately follows it, whereas I thought it would work on all data

which follows until another "setw" is encountered. What am I missing?

TIA



int IFns = 976, IPts = 130, ITms = 978;

FILE *fv = fopen("oldfile.sav", "wt");

ofstream saveFile;

saveFile.open("savefile.sav");

fprintf(fv, "%6d%6d%6d\n", IFns, IPts, ITms);

saveFile << setw(6) << IFns << IPts << ITms << endl;







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?37430-std-setw()-Not-Working&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Exception handling problem

Newsgroup: comp.lang.c++

Subject: Exception handling problem

From: woodbrian77@...

Date: Wed, 3 Jul 2013 13:33:13 -0700 (PDT)



I'm not sure if the following is due to a misunderstanding

on my part or a clang 3.2 problem. Notice the two catch

blocks below.



try{

// ...

}catch(eof const& ex){

syslog(LOG_ERR,"Got end of stream notice: %s",ex.what());

// ...

}catch(::std::exception const& ex){

syslog(LOG_ERR,"Problem handling response %s",ex.what());

// ...

}



In a test I've caused my back tier to close it's connection

to the middle tier every 500th request. The code above is

from the middle tier. I have two definitions of the eof

class:



#if 0

class eof : public failure {



public:

explicit eof (char const* what_) : failure(what_)

{}



~eof () throw()

{}

};



#else



class eof : public ::std::exception {

::std::string whatStr;



public:

explicit eof (char const* what_) : whatStr(what_)

{}



~eof () throw()

{}



char const* what () const throw()

{ return whatStr.c_str(); }



template <class T>

eof& operator<< (T val)

{

::std::ostringstream ss;

ss << val;

whatStr.append(ss.str().c_str());

return *this;

}

};



#endif



If I use the second, longer form, an eof exception is

caught as expected. But if I build the middle tier with

the shorter form of eof, the handler for std::exception

is the one used. This code and the definition of failure

is here --

http://webEbenezer.net/misc/ErrorWords.hh



I'd prefer to use the shorter form, but can't at this point.

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://www.pocketbinaries.com/usenet-forums/showthread.php?34941-Exception-handling-problem&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Saturday, July 6, 2013

Command line arguments in C++ Release configuration in Visual Studio 2008

Newsgroup: comp.lang.c++

Subject: Command line arguments in C++ Release configuration in Visual Studio 2008

From: Afshin <samansouri@...>

Date: Sat, 6 Jul 2013 05:09:33 -0700 (PDT)



Hello all,



I am struggling with defining command line arguments in C++ Release configuration in Visual Studio 2008? I can define command arguments in Debug configuration but cannot do the same in release configuration. Is there any limitation in defining command arguments in Release mode? Incidentally, I use CPLEX Concert Technology in my C++ code which is required to be compiled in Release mode.



Thanks in advance for any help.



Regards,

Afshin







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?36828-Command-line-arguments-in-C-Release-configuration-in-Visual-Studio-2008&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

baffled by 'new' operator with array type.

Newsgroup: comp.lang.c++

Subject: baffled by 'new' operator with array type.

From: Ray Dillinger <bear@...>

Date: Sat, 06 Jul 2013 02:08:25 -0700





I have the following type declarations, which I thought were quite simple;



const uint16_t SUBTREES = 64;

typedef struct stringnode *strpt; // a strpt is a pointer to a struct stringnode.

typedef strpt branchtype [SUBTREES]; // a branchtype is an array of SUBTREES strpt.





and the following function, which also seems simple. (I have added the line numbers

at the front so you can see which lines the error messages refer to).



132: // allocate and return a subtree, copied from argument within the (modular) range specified

133: branchtype *branchcopy(const branchtype * const subtrees, const int start, const int end){

134: branchtype *newbranch = new(branchtype);

135: int count;

136: for (count = start; count != end; count = (count + 1) % SUBTREES)

137: newbranch[count] = subtrees[count];

138: return(newbranch);

139: }



This function is supposed to allocate a new branchtype (via a pointer to it which is

named newbranch) and then copy a subrange of an existing branchtype (whose address

it gets via its argument subtrees) to it. The subrange copied is intended to be

'modular' in that if 'end' is less than 'start' it copies a subrange from 'start'

to the end of the array, then continues from the beginning of the array to 'end'.



When compiling this function, I get the following errors and I don't understand

what I've done wrong.



string3.cpp:133:41: error: cannot convert ?stringnode**? to ?stringnode* (*)[64]? in initialization

string3.cpp:136:38: error: invalid array assignment





I think that the first error message is baffling because it seems to imply that

new(branchtype) is returning something other than a pointer to branchtype. (ie,

in this case a pointer to an array of pointers at struct stringnodes). I can't

figure out how that could happen after reading the documentation of 'new'. I

could, but wouldn't like, to simply drop 'new' and use 'calloc' and static cast

instead.



The second error message is baffling because subtrees is a (const) pointer to (const)

branchtype and newbranch is very explicitly declared to be a pointer to branchtype,

so they are clearly the same type, and I'm trying to modify the contents of the non-

const one, not the const one. The error message is documented to mean I have

attempted to assign to an array (in violation of standard, I know), but AFAIK

there isn't anything wrong with assigning to a single element of an array. If

I understand my declarations correctly, the elements of branchtype are pointers,

not arrays. Why does it think I'm making an assignment to an array here instead

of an assignment to a pointer (which happens to be one element of an array)?



Was there something wrong with my declaration? Do these declarations not mean what

I think they mean?



Thank you for any help. I know that my style here is very C'ish and not idiomatic

C++. This code is intended to be a library that will eventually get rolled into

a 'ropes' object type (representing Unicode strings as broad, shallow trees) in C++,

but right now I'm still trying to get some fundamentals working correctly with

an absolute minimum overhead (and backporting to make a plain C library is also a

goal).



Bear









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?36767-baffled-by-new-operator-with-array-type&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Specialization of a free standing template function

Newsgroup: comp.lang.c++

Subject: Specialization of a free standing template function

From: Daniel <danielaparker@...>

Date: Fri, 5 Jul 2013 18:26:24 -0700 (PDT)



Using Visual Studio v. 10



In test.hpp:



#ifndef TEST_HPP

#define TEST_HPP



#include <ostream>



namespace ns

{

template <class T>

void serialize(std::ostream& os, const T& A)

{

os << "null";

}



template <class T>

class A

{

public:

A(const T& A)

: A_(A)

{

}

void serialize(std::ostream& os) const

{

ns::serialize(os,A_);

}



T A_;

};

}

#endif



In test.cpp:



#include "test.hpp"



namespace ns

{

template <>

void serialize(std::ostream& os, const double& A)

{

os << A;

}

}



int main()

{

ns::A<double> a(10.0);

a.serialize(std::cout);



ns::B<double> a(10.0); // *

}



This compiles and links, and the output is



10



(as expected.)



However, if I include a second cpp file in the build, and move line *

to a function in that file, I get a linker error



serialize ... already defined in test.obj



Am I doing something wrong?



Thanks,

Daniel







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?36618-Specialization-of-a-free-standing-template-function&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Friday, July 5, 2013

Lifetime of temporaries bound to references in C++11

Newsgroup: comp.lang.c++

Subject: Lifetime of temporaries bound to references in C++11

From: Michael Mehlich <michael@...>

Date: Fri, 05 Jul 2013 18:01:46 -0500



I noticed an unexpected order of destructor calls for temporaries

bound to references wrt the lifetime of the enclosing object

when experimenting with C++11 using gcc 4.9.0.



In particular, the program included below produced the output

done

~C

~B

~D

which is counter to my expectation of

done

~D

~C

~B

Looking at the C++11 standard, 12.2p5 clearly requires

~C to be called before ~B (reverse order of completion of

construction). However, the ordering of object vs. temporary

is specified wrt. the moment the object/temporary is created.

Searching the standard, it isn't clear to me when an object

or temporary is actually considered as "created", in particular

wrt. the evaluation of the constructor.



What (and where) does the standard actually say about the relative

lifetimes/ the order of destruction in this scenario?



--

Michael





extern "C" int printf(const char *, ...);



struct B {

~B() { printf("%s\n",__func__); }

int x;

int y;

};



struct C {

~C() { printf("%s\n",__func__); }

int x;

const B &b;

int y;

};



struct D {

~D() { printf("%s\n",__func__); }

int x;

const C &c;

int y;

};



int main() {

D d = { 1, { 2, { 3, 4 }, 5 } , 6 };

printf("done\n");

}



--- news://freenews.netfront.net/ - complaints: news@... ---







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?36558-Lifetime-of-temporaries-bound-to-references-in-C-11&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Derived class question

Newsgroup: comp.lang.c++

Subject: Derived class question

From: swilks06@...

Date: Fri, 5 Jul 2013 14:15:33 -0700 (PDT)



I'm trying to create a derived class called DotctorType from a base class called PersonType. I thought I was doing everything correctly, but when I complied the code I had several IntelliSense errors to pop up. I can't see what's causing the errors. Can anyone else see what I'm doing wrong? Here is the code:



01#include <string>

02#include <iostream>

03using namespace std;

04

05class PersonType

06{

07public:

08 // Function to output the first name and the last name.

09 void print() const;

10

11 //Function to set the first name and the last name.

12 void setName(string first, string last);

13

14 //Function to return the first name.

15 string getFirstName() const;

16

17 //Function to return the last name.

18 string getLastName() const;

19

20 // Constructor to set the first name and the last name.

21 PersonType(string first="", string last="");

22

23private:

24 string firstName; // Variable to store the first name.

25 string lastName; // Variable to store the last name.

26};

27

28// Function to output the first name and the last name.

29 void PersonType::print() const

30 {

31 cout<<firstName<< " "<<lastName<<endl;

32 }

33

34 //Function to set the first name and the last name.

35 void PersonType::setName(string first, string last)

36 {

37 firstName = first;

38 lastName = last;

39 }

40

41 //Function to return the first name.

42 string PersonType::getFirstName() const

43 {

44 return firstName;

45 }

46

47 //Function to return the last name.

48 string PersonType::getLastName() const

49 {

50 return lastName;

51 }

52

53 // Constructor to set the first name and the last name.

54 PersonType::PersonType(string first, string last)

55 {

56 setName(first, last);

57 }

58

59class DotorType : public PersonType

60{

61private:

62 string drtype;

63

64public:

65 string getSpeciality() const;

66 void setSpeciality(string dtype);

67 DoctorType(string first="", string last="", string type="");

68

69};

70

71string DoctorType::getSpeciality();

72{

73 return drtype;

74}

75

76void DoctorType::setSpeciality(string dtype)

77{

78 drtype = dtype;

79}

80

81

82DoctorType::DoctorType(string first="", string last="", string type="")

83 : PersonType(string first="", string last="")

84{

85 setSpeciality(type);

86}













********And here are the errors:

Error 1 error LNK2001: unresolved external symbol _mainCRTStartup`

Error 2 error LNK1120: 1 unresolved externals

3 IntelliSense: explicit type is missing ('int' assumed) (Line 67)

4 IntelliSense: name followed by '::' must be a class or namespace name (Line 71)

5 IntelliSense: expected a declaration (Line 71)

6 IntelliSense: name followed by '::' must be a class or namespace name (Line 76)

7 IntelliSense: identifier "drtype" is undefined (Line 78)

8 IntelliSense: name followed by '::' must be a class or namespace name (Line 82)

9 IntelliSense: expected a '{' (Line 83)

10 IntelliSense: identifier "setSpeciality" is undefined (Line 85)

















via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?36492-Derived-class-question&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Why doesn't implicit conversion work with wide ostream?

Newsgroup: comp.lang.c++

Subject: Why doesn't implicit conversion work with wide ostream?

From: Martin Ba <0xcdcdcdcd@...>

Date: Fri, 05 Jul 2013 16:01:06 +0200





Question @ SO:

http://stackoverflow.com/questions/17486156/why-doesnt-implicit-conversion-work-with-wide-ostream



I have some behaviour that I do not understand. I observed this on

VS2005, but [IDEONE (using GCC 4.7.2) outputs][http://ideone.com/doSHvq]

basically the same.



Here's the code:



#include <iostream>

#include <string>



struct UserString {

const char* p;

operator const char*() const {

std::cout << "! " << __FUNCTION__ << std::endl;

return p;

}



UserString()

: p ("UserString")

{ }

};



struct WUserString {

const wchar_t* p;

operator const wchar_t*() const {

std::cout << "! " << __FUNCTION__ << std::endl;

return p;

}



WUserString()

: p (L"WUserString")

{ }

};





int main() {

using namespace std;

cout << "String Literal" << endl;

cout << string("std::string") << endl;

cout << UserString() << endl;

cout << static_cast<const char*>(UserString()) << endl;



wcout << L"WString Literal" << endl;

wcout << wstring(L"std::wstring") << endl;

wcout << WUserString() << endl;

wcout << static_cast<const wchar_t*>(WUserString()) << endl;



return 0;

}



Here's the output:



String Literal

std::string

! operator const char* **** "works"

UserString ****

! operator const char*

UserString

WString Literal

std::wstring

! operator const wchar_t* **** "doesn't" - op<<(void*) is used

0x80491b0 ****

! operator const wchar_t*

WUserString





What's going on here?!?





cheers,

Martin





--

Like any language, C++ allows you to shoot yourself

in the foot -- but with C++, you sometimes don't

realize you shot yourself until it's too late. (Jeff Langr)







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?36223-Why-doesn-t-implicit-conversion-work-with-wide-ostream&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Monday, July 1, 2013

boost::asio write_some - error

Newsgroup: comp.lang.c++

Subject: boost::asio write_some - error

From: Przemek Biernat <Biernat.Przemyslaw@...>

Date: Mon, 1 Jul 2013 09:33:20 -0700 (PDT)



I have some problem with send data by boost::asio. My code:



void Connection::SendCommand(std::shared_ptr<ICommand> command)

{

int dataSize = command->GetSize();



vector<char> dataBuffer = vector<char>(dataSize);



stringstream ss;

binary_oarchive oa(ss);

command->Serialize(oa);



if(_side == Server)

command->Execute();



binary_iarchive ia(ss);



ia.load_binary(&dataBuffer[0], dataSize);



int* header = new int[3];



header[0] = (int)(command->Type());

header[1] = (int)FromClientToServer;

header[2] = dataSize;



size_t s = _socket->write_some(buffer(header, 3*sizeof(int)));

size_t s1 = _socket->write_some(buffer(dataBuffer, dataSize*sizeof(char)));



delete[] header;

}



I get exception on the second call write_some:



boost::exception_detail::clone_impl<boost::excepti on_detail::error_info_injector<boost::system::syst em_error> > at memory location 0x0021F520.



Does anybody know what is wrong?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?32879-boost-asio-write_some-error&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

New comer's question on STL/vector::data() over Dev-Cpp

Newsgroup: comp.lang.c++

Subject: New comer's question on STL/vector::data() over Dev-Cpp

From: joshipura@...

Date: Mon, 1 Jul 2013 04:01:48 -0700 (PDT)



Hello all,

I am new to C++.



Question #1: What the problem is:

============

I have Dev-Cpp 4.9.9.2 on Windows 7/64 bit.

I am trying out code from http://www.cplusplus.com/reference/vector/vector/data/ on it.

It fails with

main.cpp:42: error: 'class std::vector<int, std::allocator<int> >' has no member named 'data'



--->Is the website code wrong and there is no vector::data()?

--->Is the package of Dev-Cpp wrong?

--->Both?



Question #2: Why the problem is:

============

I need help in solving this for Sudoku solver program.

I store row, column and box as vectors and need to find an intersection of the trio.

As I understand from examples from http://www.cplusplus.com, in order to use std::set_intersection, I need to pass two arrays with lengths and a vector to store the difference.

This forces me to convert row, column and box into arrays using vector::data(), which fails.



--->Is there a way out without using vector::data()?



Thanks in advance!







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?32693-New-comer-s-question-on-STL-vector-data()-over-Dev-Cpp&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

stl::map iterator

Newsgroup: comp.lang.c++

Subject: stl::map iterator

From: HungryGoat <kumar0112@...>

Date: Sun, 30 Jun 2013 19:30:05 -0700 (PDT)



Hi, I found this code in "The C++ Standard Library" book by Nikolai.



template <class Cont>

inline bool replace_key (Cont& c,

const typename Cont::key_type& old_key,

const typename Cont::key_type& new_key)

{

typename Cont::iterator pos;

pos = c.find(old_key);

if (pos != c.end()) {

//insert new element with value of old element

c.insert(typename Cont::value_type(new_key,

pos->second));



//remove old element

c.erase(pos);

return true;

}

else {

//key not found

return false;

}

}



My question is, in the call to c.erase(pos), aren't there chances that pos is invalidated by the previous call to insert?



I am under the impression that insert or delete invalidates the iterators.



Cheers!







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?32418-stl-map-iterator&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums