Debug error abort() has been called Qt - c++

When adding this code I get the debug error. This function is called from a Dialog class if you need to see that code too I'll post it, but what I do there is convert QString to strings and int's and then call the function.
void MediaHandler::changeMedia(std::string title, std::string des, int publishYear,
int rating, std::string var1, int var2)
{
int pos = this->find(title);
Book *aBookPtr = dynamic_cast<Book*>(this->medias[pos]);
Movie *aMoviePtr = dynamic_cast<Movie*>(this->medias[pos]);
TvSeries *aTvSeriesPtr = dynamic_cast<TvSeries*>(this->medias[pos]);
if(aBookPtr != nullptr)
{
aBookPtr->setTitle(title);
aBookPtr->setDes(des);
aBookPtr->setPublishYear(publishYear);
aBookPtr->setRating(rating);
aBookPtr->setAuthor(var1);
aBookPtr->setNrOfPages(var2);
}
else if(aMoviePtr != nullptr)
{
aMoviePtr->setTitle(title);
aMoviePtr->setDes(des);
aMoviePtr->setPublishYear(publishYear);
aMoviePtr->setRating(rating);
aMoviePtr->setMainActor(var1);
aMoviePtr->setMovieLength(var2);
}
else if(aMoviePtr != nullptr)
{
aTvSeriesPtr->setTitle(title);
aTvSeriesPtr->setDes(des);
aTvSeriesPtr->setPublishYear(publishYear);
aTvSeriesPtr->setRating(rating);
aTvSeriesPtr->setMainActor(var1);
aTvSeriesPtr->setNrOfEpisodes(var2);
}
}

Related

Cannot erase a shared_ptr from set

I am trying to have an object with a set of pointers to another object. when I try to erase on of the set's values I get an error and crash, I really dont know what could be causing it. here is the library and after that the main function:
when I try to run it it does everything its supposed to do, and when it gets to the removeemployee it crashes and sends out the following: Process finished with exit code -1073740940 (0xC0000374)
I run it on clion if that matters, and in c++11.
#include <ostream>
#include <iostream>
#include "Manager.h"
Manager::Manager(int id, string firstName, string lastName, int birthYear)
: Citizen(id, firstName, lastName,birthYear), salary(0), employees(), work_flag(false) {}
int Manager::getSalary() const {
return salary;
}
void Manager::setSalary(int _salary) {
if((salary + _salary) < 0){
salary = 0;
}else {
salary += _salary;
}
}
void Manager::addEmployee(Employee* employee_add) {
shared_ptr<Employee> employee(employee_add);
if(employees.find(employee) != employees.end()){
throw mtm::EmployeeAlreadyExists();
}
employees.emplace(employee);
}
//this is the function
void Manager::removeEmployee(int id) {
for(auto it = employees.begin(); it != employees.end(); it++){
if(it->get()->getId() == id){
employees.erase(it);
return;
}
}
throw mtm::EmployeeDoesNotExists();
}
Manager *Manager::clone() {
return new Manager(*this);
}
ostream &Manager::printShort(ostream &os) const {
os<<this->getFirstName()<<" "<<this->getLastName()<<endl;
os<<"Salary :"<<this->getSalary()<<endl;
return os;
}
ostream &Manager::printLong(ostream &os) const {
os<<this->getFirstName()<<" "<<this->getLastName()<<endl;
os<<"id - "<<this->getId()<<" birth_year - "<<this->getBirthYear()<<endl;
os<<"Salary :"<<this->getSalary()<<endl;
os<<"Employees:"<<endl;
for(const auto & employee : employees){
employee->printShort(os);
}
return os;
}
bool Manager::findEmployee(int id) {
int i = 0;
for(const auto & employee : employees){
cout<<++i<<endl;
if(employee->getId() == id){
cout<<"return true"<<endl;
return true;
}
}
cout<<"return false"<<endl;
return false;
}
bool Manager::isWorkFlag() const {
return work_flag;
}
void Manager::setWorkFlag(bool workFlag) {
work_flag = workFlag;
}
and this is the main function:
int main() {
Employee e1(1, "John", "Williams", 2002);
Employee e2(2, "Alex", "Martinez", 2000);
Manager m1(1,"Robert", "stark", 1980);
m1.addEmployee(&e1);
m1.addEmployee(&e2);
Employee e3(7, "Reuven", "Guetta", 2001);
m1.addEmployee(&e3);
m1.printLong(cout);
cout<<"Delete"<<endl;
//here is the problem
m1.removeEmployee(e2.getId());
m1.printLong(cout);
return 0;
}
shared_ptr<Employee> employee(employee_add);
There is only one reason to have a shared_ptr, in the first place; there's only one reason for its existence; it has only one mission in its life, as explained in every C++ textbook: to be able to new an object, and have the shared_ptr automatically take care of deleteing it when all references to the object are gone, avoiding a memory leak.
In your program this object was not instantiated in dynamic scope with new:
Employee e2(2, "Alex", "Martinez", 2000);
Manager m1(1,"Robert", "stark", 1980);
m1.addEmployee(&e1);
// etc, etc, etc...
and that's the reason for the crash.
If you are not using new, simply get rid of all shared_ptrs in the shown code.

How do you search for a specific string in a linked list and return that value?

I have a program that takes in input with 5 parameters. The inputs are video title, url, comment, length, and rating. Then sorts them based on title. The user will need to specify insert (to enter the video information), lookup (look up a video by title and print ONLY that video and its information associated with it), or print (just simply print everything).
for example
input:
insert
Arthur Benjamin: Lightning calculation and other "Mathemagic"
http://www.youtube.com/watch?v=M4vqr3_ROIk
Hard to believe.
15.25
4
lookup
Arthur Benjamin: Lightning calculation and other "Mathemagic"
output:
Arthur Benjamin: Lightning calculation and other "Mathemagic" , http://www.youtube.com/watch?v=M4vqr3_ROIk, Hard to believe., 15.25, 4
my problem is dealing with lookup in main
if(user == "lookup")
{
getline(cin, title);
if(vlistObj -> lookup(videoObj))
{
vlistObj->print();
}
}
and also lookup in my linked list
bool Vlist::lookup(Video *other)
{
Node *node = m_head;
return node->m_next -> m_video->GetTitle() == other-> GetTitle();
}
I am honestly very lost on how to make lookup search for a specific title (assuming lots of video title/info has been given) and only print what I ask (assuming it's in the list).
Here is the complete code:
#include <iostream>
#include <stdlib.h>
#include <cstring>
using namespace std;
class Video {
public:
Video(string video_title, string video_link, string video_comment, double video_length, int video_number);
void print();
const string& GetTitle() const { return title; }
private:
std::string title;
string link;
string comment;
double length;
int rating;
};
Video::Video(string video_title, string video_link, string video_comment, double video_length, int video_number)
: title(video_title), link(video_link), comment(video_comment), length(video_length), rating(video_number)
{
}
void Video::print(){
cout << title << ", " << link << ", " << comment << ", " << length << ", " << rating << endl;
}
class Vlist {
public:
Vlist() {m_head = nullptr; }
bool lookup(Video *other);
void Insert(Video *video);
void print();
private:
class Node {
public:
Node(Video *video, Node *next) {m_video = video; m_next = next; }
Video *m_video;
Node *m_next;
};
Node *m_head;
};
void Vlist::Insert(Video* video)
{
if (m_head == NULL || m_head->m_video -> GetTitle() > video->GetTitle())
{
m_head = new Node(video, m_head);
}
else
{
Node *node = m_head;
while (node->m_next != NULL && node->m_next -> m_video->GetTitle() < video->GetTitle())
{
node = node->m_next;
}
node->m_next = new Node(video, node->m_next);
}
}
bool Vlist::lookup(Video *other)
{
Node *node = m_head;
return node->m_next -> m_video->GetTitle() == other-> GetTitle();
}
void Vlist::print()
{
Video *video;
Node *node = m_head;
while(node != NULL)
{
node -> m_video-> Video::print();
node = node->m_next;
}
}
int main()
{
string sort_type, url, comment, title, user;
int rating;
double length;
int initial = 0, last = 0, number;
Vlist *vlistObj= new Vlist();
Video *videoObj;
while (getline(cin,user)) {
if(user == "insert")
{
getline(cin,title);
getline(cin, url);
getline(cin, comment);
cin >> length;
cin >> rating;
cin.ignore();
videoObj = new Video(title,url, comment, length, rating);
vlistObj->Insert(videoObj);
}
if(user == "lookup")
{
getline(cin, title);
if(vlistObj -> lookup(videoObj))
{
vlistObj->print();
}
}
if(user == "print")
{
vlistObj->print();
}
}
}
Also I do want to note that I am receiving a segmentation fault. But I do know that it is because of my code in lookup. The program runs and output correctly if I do not type lookup
Error is in the Vlist::lookup function, where the current node pointer points to m_next which then points to m_video: m_next is not required, m_head should point directly to m_video.
Here below the complete working code, I also changed something here and there to eliminate all warnings from my compiler
#include <iostream>
#include <stdlib.h>
#include <cstring>
using namespace std;
class Video {
public:
Video(string video_title, string video_link, string video_comment, double video_length, int video_number);
void print();
const string& GetTitle() const { return title; }
private:
string title;
string link;
string comment;
double length;
int rating;
};
Video::Video(string video_title, string video_link, string video_comment, double video_length, int video_number)
: title(video_title), link(video_link), comment(video_comment), length(video_length), rating(video_number)
{
}
void Video::print(){
cout << title << ", " << link << ", " << comment << ", " << length << ", " << rating << endl;
}
class Vlist {
public:
Vlist():m_head(nullptr) {} // init_list
bool lookup(const string& title); // gets user input directly
void Insert(Video *video);
void print();
Video* get(const string& title); // new:returns pointer in list with given title
private:
class Node {
public:
Node(Video *video, Node *next):m_video(video), m_next(next) {} // init_list
Video *m_video;
Node *m_next;
} *m_head; // declared directly together with class definition
};
void Vlist::Insert(Video* video)
{
if (m_head == NULL || m_head->m_video -> GetTitle() > video->GetTitle())
{
m_head = new Node(video, m_head);
}
else
{
Node *node = m_head;
while (node->m_next != NULL && node->m_next -> m_video->GetTitle() < video->GetTitle())
{
node = node->m_next;
}
node->m_next = new Node(video, node->m_next);
}
}
bool Vlist::lookup(const string& title)
{
Node *node = m_head;
while (node->m_next != NULL && node-> m_video->GetTitle() != title)
{
node = node->m_next;
}
return node-> m_video->GetTitle() == title; // there was one pointer too many here
}
void Vlist::print()
{
Node *node = m_head;
while(node != NULL)
{
node -> m_video-> Video::print();
node = node->m_next;
}
}
Video* Vlist::get(const string& title) // returns required item from list
{
Node *node = m_head;
while (node != NULL) {
if (node->m_video->GetTitle() == title)
return node->m_video;
node = node->m_next;
}
return nullptr;
}
int main()
{
string sort_type, url, comment, title, user;
int rating;
double length;
Vlist *vlistObj= new Vlist;
Video *videoObj;
while (getline(cin,user)) {
if(user == "insert")
{
getline(cin,title);
getline(cin, url);
getline(cin, comment);
cin >> length;
cin >> rating;
cin.ignore();
videoObj = new Video(title, url, comment, length, rating);
vlistObj->Insert(videoObj);
}
if(user == "lookup") // more than a few changes here
{
getline(cin, title);
if (vlistObj -> lookup(title))
{
videoObj = vlistObj->get(title);
videoObj->print();
} else {
cout << "not found!\n";
}
}
if(user == "print")
{
vlistObj->print();
}
}
}
BIG EDIT
Previous version did not traverse the Vlist correctly.
Now Vlist is properly searched by the lookup command, that thus finally prints the correct Video.
Overview
Before looking at the specific issues, your code shows you are struggling with putting all the pieces together and are, in a sense, guessing and not paying particular attention to every line in your code. You can't code by just "trying things and see if it works", that will just make you old, gray and frustrated. Take the time to know just exactly what your next lines of code needs to do, craft the line, and then craft a test to ensure it succeeds (or make friends with gdb and check there -- you indicated you are using g++)
Examples:
#include <iostream>
#include <limits>
// #include <stdlib.h>
// #include <cstring>
What were stdlib.h and cstring included for? And:
void Vlist::print()
{
// Video *video; /* unused */
and
// int initial = 0, last = 0, number = 0; /* unused */
How is other initialized? If you are passing a pointer to a Video object, that object must at minimum have the title initialized, so GetTitle() returns a meaningful value...
bool Vlist::lookup(Video *other)
{
Node *node = m_head;
return node->m_next -> m_video->GetTitle() == other-> GetTitle();
}
That doesn't really make much sense?
Take your time and slow-down, understand what you need to do, and then pick up the keyboard (not the other way around)
Be consistent with your use of syntax. You include std::string in places and then simply string in others relying on using namespace std;. See Why is “using namespace std;” considered bad practice?
Further, under no conditions in C++ is there ever a space surrounding ->. That is an operator that joins an object and its member, with nothing in between.
Specific Issues
It is clear that what you have will not output the Video object that matches a lookup when you are attempting to print a Vlist. (doesn't make much sense to print the entire list in response to finding one title of interest). Your lookup() function cannot return bool, instead it must return a pointer to the node containing the title (if found) or nullptr if not found. That means you must save and validate the return in order to know which Node contains the record you want to print. Within main() that looks like:
else if (user == "lookup") {
if (getline(std::cin, title)) {
videoObj = new Video (title); /* you must construct a new videoObj */
Video *video = nullptr; /* you want a Video* pointer returned */
if ((video = vlistObj->lookup(videoObj))) { /* lookup & assign return */
video->print(); /* output the video, not list */
}
else {
std::cout << "title not found: '" << title << "'.\n";
}
}
}
Now that videoObj points to a Video object that has title initialized, the lookup() function can do it's job -- returning a pointer to the node within the list that contains that title (and all the rest of the information) or returning nullptr if the title isn't found. (note the else indicating to the user that condition)
A rewrite of lookup() that does just that would be:
Video *Vlist::lookup (Video *other)
{
Node *node = m_head;
while (node) { /* iterate over nodes in list looking for title */
if (node->m_video->GetTitle() == other->GetTitle())
return node->m_video; /* return pointer to node if found */
node = node->m_next;
}
return nullptr; /* nullptr if not */
}
(Note: simply passing other as std::string makes more sense, but in case you need a Video object -- this is a minimal way to do it)
There were a litany of other cleanups needed, tweaks to initializations, syntax fixes -- removing spaces around ->, etc... that are too numerous to mention. Not to mention to need to ensure you are not leaking memory -- that is left to you (and your properly written destructors) Use valgrind to verify you are freeing all memory before your program exits.
Putting the syntax clean ups and initializations together, you could do something like:
#include <iostream>
#include <limits>
class Video {
public:
Video ( std::string video_title, std::string video_link, std::string video_comment,
double video_length, int video_number );
void print();
const std::string& GetTitle() const { return title; }
private:
std::string title {}, link {}, comment {};
double length;
int rating;
};
Video::Video ( std::string video_title = "",
std::string video_link = "",
std::string video_comment = "",
double video_length = 0, int video_number = 0)
: title(video_title), link(video_link), comment(video_comment),
length(video_length), rating(video_number)
{
}
void Video::print()
{
std::cout << title << ", " << link << ", " << comment << ", " <<
length << ", " << rating << '\n';
}
class Vlist {
public:
Vlist() { m_head = nullptr; }
Video *lookup (Video *other);
void Insert (Video *video);
void print();
private:
class Node {
public:
Node (Video *video = nullptr, Node *next = nullptr) {
m_video = video; m_next = next;
}
Video *m_video;
Node *m_next;
};
Node *m_head;
};
void Vlist::Insert (Video* video)
{
if (m_head == nullptr || m_head->m_video->GetTitle() > video->GetTitle()) {
m_head = new Node (video, m_head);
}
else {
Node *node = m_head;
while (node->m_next != nullptr &&
node->m_next->m_video->GetTitle() < video->GetTitle()) {
node = node->m_next;
}
node->m_next = new Node(video, node->m_next);
}
}
Video *Vlist::lookup (Video *other)
{
Node *node = m_head;
while (node) { /* iterate over nodes in list looking for title */
if (node->m_video->GetTitle() == other->GetTitle())
return node->m_video; /* return pointer to node if found */
node = node->m_next;
}
return nullptr; /* nullptr if not */
}
void Vlist::print()
{
Node *node = m_head;
while (node != nullptr) {
node->m_video->Video::print();
node = node->m_next;
}
}
int main (void) {
std::string sort_type {}, url {}, comment {}, title {}, user {};
int rating = 0;
double length = 0;
Vlist *vlistObj = new Vlist();
Video *videoObj = nullptr;
while (getline(std::cin, user)) {
if (user == "insert") {
if (getline (std::cin, title) &&
getline (std::cin, url) &&
getline (std::cin, comment) &&
std::cin >> length &&
std::cin >> rating) {
std::cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');
videoObj = new Video (title, url, comment, length, rating);
vlistObj->Insert(videoObj);
}
}
else if (user == "lookup") {
if (getline(std::cin, title)) {
videoObj = new Video (title); /* you must construct a new videoObj */
Video *video = nullptr; /* you want a Video* pointer returned */
if ((video = vlistObj->lookup(videoObj))) { /* lookup & assign return */
video->print(); /* output the video, not list */
}
else {
std::cout << "title not found: '" << title << "'.\n";
}
}
}
else if (user == "print") {
std::cout << "\nlist content:\n";
vlistObj->print();
}
}
}
Example Input File
To minimally exercise your code you need more than one node in your linked list. What about attempting to lookup a node that does not exist -- validate that code-path?
$ cat dat/ll_video2.txt
insert
Arthur Benjamin: Lightning calculation and other "Mathemagic"
http://www.youtube.com/watch?v=M4vqr3_ROIk
Hard to believe.
15.25
4
insert
Arthur Benjamin: Some Other "Mathemagic"
http://www.youtube.com/watch?v=SomeOther
Hard to swallow.
25.25
7
lookup
Arthur Benjamin: Lightning calculation and other "Mathemagic"
lookup
Arthur Benjamin: Some Other "Mathemagic"
lookup
Mickey & Minnie do Disney
print
Example Use/Output
The results of the three lookups are handled correctly and the list contents print as they should in result to the print command input as the last line of input above:
$ ./bin/ll_video <dat/ll_video2.txt
Arthur Benjamin: Lightning calculation and other "Mathemagic", http://www.youtube.com/watch?v=M4vqr3_ROIk, Hard to believe., 15.25, 4
Arthur Benjamin: Some Other "Mathemagic", http://www.youtube.com/watch?v=SomeOther, Hard to swallow., 25.25, 7
title not found: 'Mickey & Minnie do Disney'.
list content:
Arthur Benjamin: Lightning calculation and other "Mathemagic", http://www.youtube.com/watch?v=M4vqr3_ROIk, Hard to believe., 15.25, 4
Arthur Benjamin: Some Other "Mathemagic", http://www.youtube.com/watch?v=SomeOther, Hard to swallow., 25.25, 7
Look things over and let me know if you have further questions.

Cannot dereference end list iterator

I'm currently working on a project about browser histories. I'm using the STL's list implementation to keep track of the different websites. I have most of it figured out but I can't seem to resolve the error:
Screenshot; cannot dereference end list iterator.
The website data is contained within my Site objects.
class BrowserHistory {
private:
list<Site> history;
list<Site>::iterator current = history.begin();
public:
void visitSite(string, size_t)
void backButton();
void forwardButton();
void readFile(string);
};
void BrowserHistory::visitSite(string x, size_t y)
{
while (current != history.end()) {
history.pop_back();
}
history.push_back({ x, y });
current++;
}
void BrowserHistory::backButton()
{
if (current != history.begin())
current--;
}
void BrowserHistory::forwardButton()
{
if (current != history.end())
current++;
}
void BrowserHistory::readFile(string filename)
{
string action, url;
size_t pageSize;
ifstream dataIn;
dataIn.open(filename);
while (!dataIn.eof()) {
dataIn >> action;
if (action == "visit") {
dataIn >> url >> pageSize;
history.push_back({ url, pageSize });
current++;
}
if (action == "back") {
current--;
}
if (action == "forward") {
current++;
}
}
dataIn.close();
}
Can anyone explain to me what's wrong? Thanks in advance for any help.
When you initialise current, the list is empty.
Adding elements to the list does not suddenly make it a valid iterator, even though it will be different from end.
It looks like you're thinking of iterators as very much like pointers, but they're not.
Iterators are for iterating and should be considered transient, and not stored for later use.
Use a vector, and use an index for current instead of an iterator.
Further, I would rename the "button" functions (what does the history care about buttons?) to "goBack" and "goForward" and use your actual interface when reading:
void BrowserHistory::readFile(string filename)
{
ifstream dataIn(filename);
string action;
while (dataIn >> action) {
if (action == "visit") {
string url;
size_t pageSize;
if (dataIn >> url >> pageSize) {
visitSite(url, pageSize);
}
else {
// Handle error
}
}
else if (action == "back") {
goBack();
}
else if (action == "forward") {
goForward();
}
else {
// Handle error
}
}
}

How do I return a Null Pointer in a function C++

I am currently working on a bit of code that will search within a vector of type Person (which I have defined in the code and will show if needed). If it finds the person, it returns their name. This is currently working, but if it does not find the person, it is supposed to return a Null pointer. The problem is, I cannot figure out how to make it return a Null pointer! It just keeps either crashing the program every time.
Code:
Person* lookForName(vector<Person*> names, string input)
{
string searchName = input;
string foundName;
for (int i = 0; i < names.size(); i++) {
Person* p = names[i];
if (p->getName() == input) {
p->getName();
return p; //This works fine. No problems here
break;
} else {
//Not working Person* p = NULL; <---Here is where the error is happening
return p;
}
}
}
You could use std::find_if algorithm:
Person * lookForName(vector<Person*> &names, const std::string& input)
{
auto it = std::find_if(names.begin(), names.end(),
[&input](Person* p){ return p->getName() == input; });
return it != names.end() ? *it : nullptr; // if iterator reaches names.end(), it's not found
}
For C++03 version:
struct isSameName
{
explicit isSameName(const std::string& name)
: name_(name)
{
}
bool operator()(Person* p)
{
return p->getName() == name_;
}
std::string name_;
};
Person * lookForName(vector<Person*> &names, const std::string& input)
{
vector<Person*>::iterator it = std::find_if(names.begin(), names.end(),
isSameName(input));
return it != names.end() ? *it : NULL;
}
If the name you are searching for is not at the first element, then you are not searching in the rest of the elements.
You need to do something like -
for (int i = 0; i<names.size(); i++){
Person* p = names[i];
if (p->getName() == input) {
return p;
// Placing break statement here has no meaning as it won't be executed.
}
}
// Flow reaches here if the name is not found in the vector. So, just return NULL
return NULL;
As Chris suggested, try using std::find_if algorithm.
Looks like you just have to return Null, nullptr, or 0.
codeproject
Just use following code:
return NULL;

std::list iterator

The following code instead of returning a pointer back to an audioResource it returns
something else which is invalid, i've gone through with a debugger and the problem is with this line
return *list_it;
Here is my function:
AudioResource* AudioManager::getResource(const unsigned int ID)
{
std::list<AudioResource*>::iterator list_it;
for(list_it = m_resources.begin(); list_it!= m_resources.end(); list_it++)
{
if((*list_it)->getID()==ID)
{
std::cout<<*(*list_it)->getFileName();
return *list_it;
}
}
return nullptr;
}
O and I have tried putting it as (*list_it) but i got the same results =s
How it is populated...
Resource* AudioManager::addResource(const unsigned int ID,
const std::string fileName, const unsigned int scope,
const std::string type)
{
AudioResource* temp;
if(type == "AUDIO_TYPE_SAMPLE")
{
temp = new AudioResource(ID,fileName,scope,
RESOURCE_AUDIO,AUDIO_TYPE_SAMPLE);
m_resources.push_back(temp);
}
else if(type == "AUDIO_TYPE_STREAM")
{
temp = new AudioResource(ID,fileName,scope,
RESOURCE_AUDIO,AUDIO_TYPE_STREAM);
m_resources.push_back(temp);
}
return temp;
}
call to get resource
cout<<AudioManager::getInstance()->getResource(IDnum)->getFileName();
If type is neither of the two values an uninitialized pointer is added to m_resources:
AudioResource* temp;
if(type == "AUDIO_TYPE_SAMPLE")
{
temp = new AudioResource(ID,fileName,scope,RESOURCE_AUDIO,AUDIO_TYPE_SAMPLE);
}
else if(type == "AUDIO_TYPE_STREAM")
{
temp = new AudioResource(ID,fileName,scope,RESOURCE_AUDIO,AUDIO_TYPE_STREAM);
}
m_resources.push_back(temp);
Initialize temp to NULL and only add to m_resources if temp != NULL.
Also, the function returns the same uninitialized pointer.
You return nullptr in case the ID doesn't exist, but you never check against it at the call site, which will give you a null pointer access if the ID doesn't exist and which will likely create problems.
AudioManager::getInstance()->getResource(IDnum)->getFileName();
Change that to
AudioResource* res = AudioManager::getInstance()->getResource(IDnum);
if(res)
std::cout << res->getFileName();