Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

primary expression

42 views
Skip to first unread message

ruben safir

unread,
Nov 20, 2016, 10:48:25 PM11/20/16
to
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

woodb...@gmail.com

unread,
Nov 20, 2016, 11:29:14 PM11/20/16
to
On Sunday, November 20, 2016 at 9:48:25 PM UTC-6, ruben safir wrote:
> 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} } ;

How about this:

parent * tmp2{tmp};

?

Popping mad

unread,
Nov 21, 2016, 2:07:50 AM11/21/16
to

Popping mad

unread,
Nov 21, 2016, 2:09:55 AM11/21/16
to
On Sun, 20 Nov 2016 20:29:03 -0800, woodbrian77 wrote:

> On Sunday, November 20, 2016 at 9:48:25 PM UTC-6, ruben safir wrote:
>> 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} } ;
>
> 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

unread,
Nov 21, 2016, 2:17:18 AM11/21/16
to
That it does, what on Earth are you trying to do there?

Please stick to one posting alias!

--
Ian

Chris Vine

unread,
Nov 21, 2016, 8:19:40 AM11/21/16
to
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.

Alf P. Steinbach

unread,
Nov 21, 2016, 9:06:28 AM11/21/16
to
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

unread,
Nov 21, 2016, 3:54:49 PM11/21/16
to
On 11/21/2016 08:17 AM, Chris Vine wrote:
> On Sun, 20 Nov 2016 22:48:16 -0500
> ruben safir <ru...@mrbrklyn.com> wrote:
>> 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
>
> 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.


I am relearning C++ after a 6 year lay off. And BTW, the compiler is
probably the best instructor for C and C++

ruben safir

unread,
Nov 21, 2016, 3:56:08 PM11/21/16
to
On 11/21/2016 08:17 AM, Chris Vine wrote:
> ng 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.


right. I thought that is the syntax, but I misunderstood. Thank you,

Ruben

Öö Tiib

unread,
Nov 21, 2016, 5:07:41 PM11/21/16
to
On Monday, 21 November 2016 22:54:49 UTC+2, ruben safir wrote:
> On 11/21/2016 08:17 AM, Chris Vine wrote:
> > On Sun, 20 Nov 2016 22:48:16 -0500
> > ruben safir <ru...@mrbrklyn.com> wrote:
> >> 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
> >
> > 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.
>
>
> I am relearning C++ after a 6 year lay off. And BTW, the compiler is
> probably the best instructor for C and C++

Compiler is definitely worst instructor of those two languages whose
*every* feature contains a number of related undefined behaviors that
tools are not obliged to diagnose.

You can not find out about undefined behavior using compiler.
Undefined behavior sometimes results with a program that sometimes
appears to work or even that most of the time appears to work. So
the result of your voodoo programming is often somewhat unstable
program that acts in somewhat insane manner and your own poisoned
brains with misinformation about what voodoo spells work in C++.

Louis Krupp

unread,
Nov 21, 2016, 5:18:57 PM11/21/16
to
On Mon, 21 Nov 2016 15:54:40 -0500, ruben safir <ru...@mrbrklyn.com>
wrote:

<snip>
>I am relearning C++ after a 6 year lay off. And BTW, the compiler is
>probably the best instructor for C and C++

The compiler might have better social skills than some of us on this
newsgroup, but I wouldn't call it a good instructor. It's kind of
terse.

I have a copy of Stephen Prata's C++ Primer Plus, Sixth Edition, 2012,
and it covers at least some of what's changed in C++11. Amazon lists
other titles. Read the reviews, buy whatever looks good from Amazon or
locally, and happy reading.

Louis

JiiPee

unread,
Nov 21, 2016, 5:29:15 PM11/21/16
to
On 21/11/2016 22:18, Louis Krupp wrote:
> The compiler might have better social skills than some of us on this
> newsgroup


Yes, at least it is always 100% truthfull :). It does not tell lies...

JiiPee

unread,
Nov 21, 2016, 5:30:05 PM11/21/16
to
On 21/11/2016 22:18, Louis Krupp wrote:
> I have a copy of Stephen Prata's C++ Primer Plus,


that was my first C++ book back in 1996 I bought, to learn C++. It was
good then... I liked it. I learned well using it. i tried also others
but this was best for me.

Christopher J. Pisz

unread,
Nov 21, 2016, 6:12:46 PM11/21/16
to
I learned C++ from this newsgroup, Victor, Alf, and Oo Tiib.

Popping mad

unread,
Nov 21, 2016, 6:40:51 PM11/21/16
to
On Mon, 21 Nov 2016 15:18:47 -0700, Louis Krupp wrote:


> The compiler might have better social skills than some of us on this
> newsgroup, but I wouldn't call it a good instructor. It's kind of terse.
>
> I have a copy of Stephen Prata's C++ Primer Plus, Sixth Edition, 2012,
> and it covers at least some of what's changed in C++11. Amazon lists
> other titles. Read the reviews, buy whatever looks good from Amazon or
> locally, and happy reading.

Thanks

Currently I'm working with Stroustrup 4th edition, Guntheroth Optimized C+
+ 1st ed, Williams, C++ Concunrancy 2012, Vandevoodre Templates 12th
print 2010, Lipman and Lajoie C++ primer3rd edition 1998, Corman
Allgorithms and a few other texts on PNG, a C++ with pthreads and using
GCC by RMS

Jerry Stuckle

unread,
Nov 21, 2016, 9:25:22 PM11/21/16
to
You have my sympathy...

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstu...@attglobal.net
==================

Louis Krupp

unread,
Nov 22, 2016, 1:43:25 AM11/22/16
to
Based on reviews of Stroustrup's book, I would recommend reading
something simpler but up to date first. Then, when you run into
something that doesn't work the way you expect it to, take some time
to figure it out using just your experience, the books, and whatever
information you can find online. Don't post anything unless you're
really desperate.

Believe it or not, this is more or less what programmers did for
hundreds (OK, dozens) of years before Internet. We couldn't look stuff
up online because there was no such thing, and we certainly couldn't
ask anyone unless they were down the hall and we could walk into their
office and show them a listing (when we printed a program, we called
it a listing) or write stuff on their whiteboard, but that was only if
they had a whiteboard. Whiteboards weren't really a thing in a lot of
places until about 25 or 30 years ago. So we read books and manuals
and we reread them and we read programs that other people had written
and which worked and we tried things and eventually we figured stuff
out, and we were proud of ourselves.

It might be frustrating at first, but you'll get good at it, and then
when other people post questions, you'll be the one posting answers.

Louis



ruben safir

unread,
Nov 22, 2016, 11:51:42 AM11/22/16
to
On 11/22/2016 01:43 AM, Louis Krupp wrote:
> Believe it or not, this is more or less what programmers did for
> hundreds (OK, dozens) of years before Internet. We couldn't look stuff
> up online because there was no such thing, and we certainly couldn't
> ask anyone unless they were down the hall and we could walk into their
> office and show them a listing (when we printed a program, we called
> it a listing) or write stuff on their whiteboard, but that was only if
> they had a whiteboard. W


back then. when I used to program, first of all the languages were far
simpler and secondly I had access to a broad range of coworkers and
student. But that was a long time ago, and it wasn't unusual to work
with punch cards. Our workspace was freezing because of the the AC, and
we had to maintain a lot of the HW. SInce the mid-1990's we've had
access to usenet and sometimes irc.
0 new messages