Error 1 error LNK2019: unresolved external symbol "public: void __thiscall Sounds::soundBox(void)" (?soundBox@Sounds@@QAEXXZ) referenced in function _main
For some reason i get this error, and i rly dont know what i did wrong. Got wimm.lib added playsound works when called from main() When i try to call it from class in playsound.cpp it calls error...
playsounds.h
#pragma once
#include <Windows.h>
class Sounds
{
public:
Sounds();
~Sounds();
void soundBox();
};
playsound.cpp
#include "playsound.h"
Sounds::Sounds()
{
}
void soundBox()
{
PlaySound(TEXT("fx/boom1.wav"), NULL, SND_FILENAME);
}
Sounds::~Sounds()
{
}
main.cpp
#include <iostream>
#include <conio.h>
#include "playsound.h"
int main()
{
Sounds newsound;
newsound.soundBox();
_getch();
}
You need to change the function definition in playsound.cpp
void soundBox()
To
void Sounds::soundBox()
This is because the function exists within the scope of the Sounds
class, so you have to define it as such. Otherwise it would be a free function, and the version of the function in your Sounds
class would be undefined (which is what the error is telling you).