Iam trying to make this really simple(atleast thats what I thought) program to put books in a vector. Then also add some more stuff but first things first.
If I do it in main, it works(See the multicomment at the bottom)
But I wanna do it via a memberfunction from the Library class. I dont get any errors in the IDE but when I run the code I get three errors from line 12
Errors :
Error C3861 'b2': identifier not found
Error C2065 'Book': undeclared identifier
Error C2146 syntax error: missing ';' before identifier 'b2'
I have tried so many things to get this to work but I cant get around it, feels like Im missing some simple detail, or Im totally out swimming on the whole program.
#include "pch.h"
#include <iostream>
#include <vector>
#include <string>
class Library
{
public:
void createBook(std::string title, int isbn, int count)
{
//Error on line 12 when debugging
Book b2(title, isbn, count);
}
};
class Book
{
private:
std::string title;
int ISBN;
int count;
public:
Book(std::string Title, int iSBN, int Count)
{
title = Title;
ISBN = iSBN;
count = Count;
}
};
int main()
{
Library library;
std::vector<Book>allBooks;
std::string title;
int ISBN;
int count;
std::cout << "Enter titel : ";
std::cin.ignore();
getline(std::cin, title);
std::cout << "Enter ISBN : ";
std::cin >> ISBN;
std::cout << "Enter total : ";
std::cin >> count;
//This works and puts the book in the vector 'allBooks'
/*
Book b1(title, ISBN, count);
allBooks.push_back(b1);
*/
library.createBook(title, ISBN, count);
}