•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 425,995 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,664 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 781 | Replies: 2
![]() |
•
•
Join Date: Jul 2006
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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:
#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 10: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 : Jul 31st, 2006 at 11:11 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- A Basic Question. . . (Windows 9x / Me)
- C compiler help (beginner question) (C++)
Other Threads in the C++ Forum
- Previous Thread: Help With Sftp In C++
- Next Thread: Console setting



Linear Mode