#include <iostream>
#include <stdlib.h>
#include <time.h>
usingnamespace std;
constant int MAX = 10;
class Corge
{
public:
string name;
int number;
Corge();
};
class Foobar
{
public:
Corge waldo[MAX];
void create()
{
srand(time(0));
int random;
random = rand()%(1000);
waldo[0].number = random;
cout << "Enter name: ";
cin >> waldo[0].name;
}
}
int main()
{
int user(1);
Foobar garply;
do
{
cout << "Press 1 to create new object: ";
cin >> user;
switch(user)
{
case 1:
graply.create();
default:
cout << "Program END";
}
}while(user == 1)
}
How do I make the program choose a "new" spot for the new object?
I tried the code above and did a quick print of all objects, and discovered that if i create a new object and name it Nick, then create another object and name it Marcus, then print them the only object remaining is Marcus on the spot where Nick should be.
The only reason I can think of is that I create all objects at waldo[0]. But I dont know what else to do?
..\zinjai\sin_titulo.cpp:7:1: error: 'constant' does not name a type
..\zinjai\sin_titulo.cpp:20:15: error: 'MAX' was not declared in this scope
..\zinjai\sin_titulo.cpp:34:2: error: expected ';' after class definition
..\zinjai\sin_titulo.cpp: In member function 'void Foobar::create()':
..\zinjai\sin_titulo.cpp:29:4: error: 'waldo' was not declared in this scope
..\zinjai\sin_titulo.cpp: In function 'int main()':
..\zinjai\sin_titulo.cpp:49:5: error: 'graply' was not declared in this scope
..\zinjai\sin_titulo.cpp:55:1: error: expected ';' before '}' token
..\zinjai\sin_titulo.cpp:39:9: warning: unused variable 'garply' [-Wunused-variable]
Why you post code with simple errors and ask complicated question?
"constant" isn't a keyword!
Fix those errors get this.
../zinjai/sin_titulo.cpp:17: undefined reference to `Corge::Corge()'