Hi everyone!
Until now, I've almost only programmed in Java and am now learning C++ (using Bjarne Stroustrup's book). Now, I wanted to test one of the examples from the book, but somehow it doesn't work as it should.
Here's my code, reduced to the most simple elements:
[code=c++]
#include <iostream>
#include <stdexcept>
using namespace std;
vector<int> myVec(100);
int main()
{
for(int i=0; i<26; i++)
{
myVec[i]=i;
}
}
[/code]When trying to compile it with g++, I get: (translated from german)
Here, line 12 is the line "vector<int > myVec(100);" and line 23 is "myVec[i]=i;".
In Java, I would guess, that a line like
[code=java]
myVec = new Vec<int>();
[/code]was missing, but as it's not in the book, there must be some other error.
I'm sure, the error is really simple, but I just can't find it. Who will solve the mystery for me?
Greetings,
Nepomuk
Until now, I've almost only programmed in Java and am now learning C++ (using Bjarne Stroustrup's book). Now, I wanted to test one of the examples from the book, but somehow it doesn't work as it should.
Here's my code, reduced to the most simple elements:
[code=c++]
#include <iostream>
#include <stdexcept>
using namespace std;
vector<int> myVec(100);
int main()
{
for(int i=0; i<26; i++)
{
myVec[i]=i;
}
}
[/code]When trying to compile it with g++, I get: (translated from german)
Code:
vectorTest.cpp:12: Error: expected constructor, destructor, or type conversion before »<« token vectorTest.cpp: In function »int main()«: vectorTest.cpp:23: Error: »myVec« was not defined in this scope
In Java, I would guess, that a line like
[code=java]
myVec = new Vec<int>();
[/code]was missing, but as it's not in the book, there must be some other error.
I'm sure, the error is really simple, but I just can't find it. Who will solve the mystery for me?
Greetings,
Nepomuk
Comment