what POINT am I missing ?

This is a discussion on what POINT am I missing ? within the C++ Programming forums, part of the General Programming Boards category; hi, I've tried searching around with no luck, I have seen this referenced/suggested in a (old) thread in forum somewhere, ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Location
    Australia
    Posts
    55

    what POINT am I missing ?

    hi,
    I've tried searching around with no luck, I have seen this referenced/suggested in a (old) thread in forum somewhere, a book I have even structures the following this way but I can't seem to figure out why following won't work (i.e. won't compile):
    Code:
    	POINT points[2];
    	points[0] = {50,75};
    	points[1] = {75,100};
    	Polygon(hDC, points, 2);
    I get an "expected primary-expression before '{' token" error, but I don't/can't see how/why. This is the only code present & there's nothing else that affects this.

    Am I missing something?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,931
    You are trying to use brace enclosed initialiser lists for assignment when they are supposed to be used for initialisation. Try:
    Code:
    POINT points[] = {{50, 75}, {75, 100}};
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2008
    Location
    Australia
    Posts
    55
    I realise that I can initialise/set the POINTS that way. I was trying to understand why the book I was reading & another (old) thread I came across, specifically had it laid out like this, but wasn't working for myself. Thought maybe I had missed something entirely

    So I'm guessing that it is incorrect, yes. Frustrating when you're trying to learn something & it's wrong

    Thanks!

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    This syntax should work in C++0x, which changes the rules how braces can be used for initializing objects.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,931
    Quote Originally Posted by anon
    This syntax should work in C++0x, which changes the rules how braces can be used for initializing objects.
    But the syntax in Tropod's post concerns assignment, not initialisation.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    The larch
    Join Date
    May 2006
    Posts
    3,573
    It compiles with GCC, and I assume it is initializing a temporary, then copying it for assignment.

    May-be the compiler is wrong, but it is quite explicitly telling me that "extended initializer lists" are available only in the -std=c++0x mode.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,931
    Quote Originally Posted by anon
    It compiles with GCC, and I assume it is initializing a temporary, then copying it for assignment.
    Oh yeah, that is certainly possible.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,785
    Quote Originally Posted by anon View Post
    It compiles with GCC, and I assume it is initializing a temporary, then copying it for assignment.
    That should be possible with C++0x, I guess, but not with C++03.
    GCC is also the only compiler I know that supports initializer lists (the C++0x feature).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    I don't see how this could compile, that rvalue is type-ambiguous...

  10. #10
    Registered User
    Join Date
    Apr 2008
    Location
    Australia
    Posts
    55
    So wait, now I'm (really) confused .......

    I currently have wxDevC++ 7.2.0.2 installed, with this issue. I also have another separate program/compile issue that I'm trying to deal with (linker related perhaps), so it's quite possible I may have an issue with my compiler, sssoooo.......

    Is the initial code I posted legal or not? The book I have was printed in 2005, is someone please able to clarify


    Thanks!!

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,931
    Quote Originally Posted by Tropod
    Is the initial code I posted legal or not?
    At the moment, it is not legal.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,785
    Quote Originally Posted by BMJ View Post
    I don't see how this could compile, that rvalue is type-ambiguous...
    Why is it ambiguous? It should be a initializer_list with int.
    In C++03, it's simply illegal.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    But it's not an initialization, it's an assignment?

    I've been trying to find proof that this is legal in C++0x but I haven't had any success. Care to point me in the right direction?

    Thanks.

  14. #14
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,931
    Quote Originally Posted by BMJ
    I've been trying to find proof that this is legal in C++0x but I haven't had any success. Care to point me in the right direction?
    Read clause 8.5.4 of a recent draft of the next version of the C++ standard. Paragraph 1 has a note that "List-initialization can be used (...) on the right-hand side of an assignment". Also, refer to the examples of assignment in clause 5.17 paragraph 9.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  15. #15
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    Ah, thank you! That's exactly what I was looking for.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing Program
    By Max_Payne in forum C++ Programming
    Replies: 21
    Last Post: 12-21-2007, 04:34 PM
  2. Classes & Collections
    By Max_Payne in forum C++ Programming
    Replies: 7
    Last Post: 12-11-2007, 12:06 PM
  3. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  4. Help with a Class
    By maloy in forum C++ Programming
    Replies: 12
    Last Post: 09-27-2002, 08:41 PM
  5. odd errors from msvc std library files
    By blight2c in forum C++ Programming
    Replies: 6
    Last Post: 04-30-2002, 12:06 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21