- a problem about programming - 5 Updates
- Custom Memory Manager & placement new - 1 Update
- the new {} syntax - 3 Updates
- hidden static - 1 Update
- primary expression - 6 Updates
- Failed interview test - 2 Updates
Louis Krupp <lkrupp@nospam.pssw.com.invalid>: Nov 23 01:54PM -0700 >but change only 1 symbol (the last) and I have hundred symbols. >Maybe the problem iis in the FOR cycle. >Can you help me? Only if you show me your code. I did notice something about what you posted earlier: for( i = Qty - 1; i >= 0; i = i - 1 ) { st = sts.Item( i ); Ticker = st.Ticker; ** This variable 'Ticker' starts with an upper case 'T' printf("changing " + ticker + "\n" ); ** This one stars with a lower case 't' Length = StrLen(Ticker ); ** Upper case if( StrFind(ticker, ".TO") ) st.Ticker = StrLeft( ticker, Length-3)+"-TC"; ** Lower case } Do you really have two variable, 'Ticker' and 'ticker'? Where do you assign a value to 'ticker' with a lower case 't'? Could this be part of your problem? Louis |
Lino <lino@net.com>: Nov 23 10:46PM +0100 > assign a value to 'ticker' with a lower case 't'? Could this be part > of your problem? > Louis ok I have corrected the script: ------------------------------------------- AB = CreateObject("Broker.Application"); sts = AB.Stocks(); Qty = sts.Count; for( i = Qty - 1; i >= 0; i = i - 1 ) { st = sts.Item( i ); Ticker = st.Ticker; printf("changing " + Ticker + "\n" ); Length = StrLen(Ticker ); if( StrFind(Ticker, "BIT:") ) st.Ticker= "TC-"+StrRight(Ticker,Lenght+3); } ------------------------------------------- this (below) work partially and it have 2 problem: ----> st.Ticker= "IT_"+StrRight(ticker,Lenght+3); 1. change only 1 symbol a time (I think it's a "FOR Cycle" problem) 2. Example: I have symbols [below] -----> and result TO:A TC-T:A wrong TO:DE TC-:DE wrong TO:ASD TC-ASD OK OK OK OK TO:AXMA TC-XMA Wrong TO:ERJTT TC-JTT wrong I want to change "only" the "TO:" or the part of string that I want to change leaving the rest the same as originally printed. Hope I'an clear. Tell me a specific question to clarify it myself. Thanks for help. Lino. |
Lino <lino@net.com>: Nov 23 10:48PM +0100 Corrected : if( StrFind(Ticker, "TO-") ) |
Lino <lino@net.com>: Nov 23 10:53PM +0100 Dopo dura riflessione, Lino ha scritto : > Corrected : if( StrFind(Ticker, "TO-") ) TO: |
Louis Krupp <lkrupp@nospam.pssw.com.invalid>: Nov 23 04:05PM -0700 >Dopo dura riflessione, Lino ha scritto : >> Corrected : if( StrFind(Ticker, "TO-") ) >TO: Does it work? If so, congratulations! If not, please post your code and your results. Louis |
"Chris M. Thomasson" <invalid@invalid.invalid>: Nov 23 01:24PM -0800 On 11/22/2016 1:06 PM, Christopher J. Pisz wrote: > what new and delete normally do is going to save you. Maybe you have to > only use specific locations, but similar to the previous question, why > would that happen? I remember a long time ago when I was exploring custom allocators in C++: https://groups.google.com/d/topic/comp.lang.c++/48Tm8j8ag-0/discussion The program had no undefined behavior and was confirmed as a compiler bug in MSVC 8 and 9 by James Kanze: https://groups.google.com/forum/#!original/comp.lang.c++/48Tm8j8ag-0/o8GXMeZG1fwJ A quote from the post linked above: ________________________________________ Well, there's no undefined behavior. You're program seems perfectly legal and well defined to me. It looks like a bug in VC++, see =A712.5/5: When a delete-expression is executed, the selected deallocation function shall be called with the address of the block of storage to be reclaimed as its first argument and (if the two-parameter style is used) the size of the block as its second argument. And I can't think of any way of interpreting "the size of the block" to mean anything other than the size requested in the call to operator new. ________________________________________ This was back when I was still trying out custom allocation techniques in C++. |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Nov 21 03:01PM +0100 s/you/Louis/g @Ruben: Your own fault for removing all context, heh. On 21.11.2016 14:59, Alf P. Steinbach wrote: |
Popping mad <rainbow@colition.gov>: Nov 21 03:10AM why doesn't this enter the second constructor? 18 #include<iostream> 19 20 class parent{ 21 public: 22 parent():_something{nullptr}, _val{0} { 23 std::cout << "null constructor\n"; 24 }; 25 parent(parent *in):_something{in}, _val{10} { 26 std::cout << "here\n"; 27 _something->_val = 0; 28 }; 29 parent * _something; 30 int _val; 31 }; 32 void discover(parent * in){ 33 std::cout<< in->_val << std::endl; 34 std::cout<< in->_something->_val << std::endl; 35 } 36 37 int main(int argc, char **argv) 38 { 39 parent * tmp = new parent; 40 parent * tmp2{tmp}; 41 //parent * tmp2 = new parent(tmp); 42 discover(tmp2); 43 44 45 46 return EXIT_SUCCESS; 47 } [ruben@flatbush max_path]$ g++ -Wall test.cpp [ruben@flatbush max_path]$ ./a.out null constructor 0 Segmentation fault |
Louis Krupp <lkrupp@nospam.pssw.com.invalid>: Nov 20 09:06PM -0700 On Mon, 21 Nov 2016 03:10:01 +0000 (UTC), Popping mad >null constructor >0 >Segmentation fault Because "parent * tmp2{tmp}" isn't constructing a new parent object; if I'm not mistaken, tmp2 is going to be of type parent * and a copy of tmp. Try this: 1 #include<iostream> 2 3 class parent{ 4 public: 5 parent():_something{nullptr}, _val{0} { 6 std::cout << "null constructor\n"; 7 }; 8 parent(parent *in):_something{in}, _val{10} { 9 std::cout << "here\n"; 10 _something->_val = 0; 11 }; 12 parent * _something; 13 int _val; 14 }; 15 void discover(parent * in){ 16 std::cout<< in->_val << std::endl; 17 std::cout<< in->_something->_val << std::endl; 18 } 19 20 int main() 21 { 22 parent * tmp = new parent; 23 parent tmp2{tmp}; 24 //parent * tmp2 = new parent(tmp); 25 discover(&tmp2); 26 27 return 0; 28 } Louis |
scott@slp53.sl.home (Scott Lurndal): Nov 21 01:26PM >A static member variable needs to exist somewhere in the executable >(because, among other things, you need to be able to eg. have a pointer >pointing to it). The confusing part for some folks is that gcc/binutils, when using -O3, won't require the definition unless the address of the static const value is taken. Remove -O3 and you'll start getting link errors. |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Nov 21 03:03PM +0100 On 21.11.2016 04:48, ruben safir wrote: >>> 40 parent * tmp2{ parent _a{tmp} } ; > 41 //parent * tmp2 = new parent(tmp); > line 40 needs a primary expression before _a A primary expression is an expression. A declaration -- what you have placed within the curly braces -- is not an expression. Cheers & hth., - Alf |
ruben safir <ruben@mrbrklyn.com>: Nov 20 10:48PM -0500 What is a primary express in the context of this 37 int main(int argc, char **argv) 38 { 39 parent * tmp = new parent; >> 40 parent * tmp2{ parent _a{tmp} } ; 41 //parent * tmp2 = new parent(tmp); line 40 needs a primary expression before _a |
Popping mad <rainbow@colition.gov>: Nov 21 07:07AM What is a primary express in the context of this |
Popping mad <rainbow@colition.gov>: Nov 21 07:09AM On Sun, 20 Nov 2016 20:29:03 -0800, woodbrian77 wrote: >> >> 40 parent * tmp2{ parent _a{tmp} } ; > How about this: > parent * tmp2{tmp}; aside from the fact that it doesn't address my question, It also doesn't allocate anything. |
Ian Collins <ian-news@hotmail.com>: Nov 21 08:17PM +1300 On 11/21/16 04:48 PM, ruben safir wrote: >>> 40 parent * tmp2{ parent _a{tmp} } ; > 41 //parent * tmp2 = new parent(tmp); > line 40 needs a primary expression before _a That it does, what on Earth are you trying to do there? Please stick to one posting alias! -- Ian |
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Nov 21 01:17PM On Sun, 20 Nov 2016 22:48:16 -0500 > >> 40 parent * tmp2{ parent _a{tmp} } ; > 41 //parent * tmp2 = new parent(tmp); > line 40 needs a primary expression before _a You seem to be trying to learn C++ by trial and error with a compiler. That is a hopeless way of trying to do it. You are getting unnecessarily confused by the basics - in this case between a type and a pointer to the type. You may also be confused by the syntactic difference between a pointer and a reference. Get yourself a decent book (or even a poor one would still be better than trying to learn the language your way). Assuming you and "Popping mad" are the same person and you are referring to the parent class in his post "the new {} syntax", your problem is that you are trying to initialize a parent* object 'tmp2' with something other than an address of a parent object. (The syntax is also invalid for other reasons, but the foregoing appears to be the principal source of your confusion.) To take an address of an object you use the '&' operator. Sticking to a single identity would also serve to reduce the confusion you may induce in your readers. |
ram@zedat.fu-berlin.de (Stefan Ram): Nov 22 11:50PM >unspecified behavior >behavior, for a well-formed program construct and correct data, that >depends on the implementation This defines »unspecified behavior«, not »unspecified«. »Unspecified« means »unspecified« as in English, there is no need to define it. »Unspecified« = »not specified«, the meaning of »specified« derives regularly from the meaning of »to specify«. The first sentence of our beloved standard is: »This International Standard specifies requirements for implementations of the C++ programming language.« . This sentence already uses the verb »to specify«, and when someone does not know what this means, he needs to learn English. |
ram@zedat.fu-berlin.de (Stefan Ram): Nov 21 09:20AM >Ben Bacarisse <ben.usenet@bsb.me.uk> writes: >>Is nullptr not a pointer? >std::nullptr_t is a distinct type that is neither a pointer main.cpp #include <iostream> #include <ostream> #include <type_traits> template< typename T > void describe( T const ) { ::std::cout << ::std::is_pointer< T >::value << '\n'; } int main() { describe( nullptr ); } transcript 0 |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment