| | |
C++ beginner's question
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Hello,I have just started to learning C++. I have a question regarding a small code snippet that I am having trouble with. I get a compiler error saying that there is a parse error before the { token. Can anyone help me with this?
Thanks,
Navid
Here's the code:
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main() { struct CandyBar { string brand; int calories; float weight; }; CandyBar *snack = new CandyBar[3]; snack[0] = {"Milky Way", 350, 2.3}; //**Error before { token snack[1] = {"Hershey's", 400, 3.3}; snack[2] = {"Dove", 450, 4.3}; delete [] snack; return 0; }
Last edited by Dave Sinkula; Jul 31st, 2006 at 11:58 pm. Reason: Added [code][/code] tags -- learn to use them yourself.
You can initialize elements like that, but you are trying to assign them, which you cannot do. You can assign each member individually.
Last edited by Dave Sinkula; Aug 1st, 2006 at 12:11 am.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- A Basic Question. . . (Windows 95 / 98 / Me)
- C compiler help (beginner question) (C++)
Other Threads in the C++ Forum
- Previous Thread: Help With Sftp In C++
- Next Thread: Console setting
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






