class - Accessing classes from another source in C++, issues initializing the constructor -
class - Accessing classes from another source in C++, issues initializing the constructor -
i have class called player has constructor takes 5 float parameters declared in "player.h" file , initialized in "player.cpp" file shown @ bottom of post.
whenever seek run program, error:
build/debug/mingw-windows/player.o: in function `player': c:\users\user\dropbox\netbeans workspace\testing/player.cpp:11: multiple definition of `player::player(float, float, float, float, float)' build/debug/mingw-windows/main.o:c:\users\user\dropbox\netbeans workspace\testing/player.h:20: first defined here
what doing wrong here? tried getting rid of "public:" before constructor, didn't help @ all. says have multiple definitions of constructor, initialize once. sure obvious.
the finish source of 2 files:
"player.cpp"
#include "player.h" player::player(float x, float y, float z, float rx, float ry) { }
"player.h"
#ifndef player_h #define player_h class player { public: player(float x, float y, float z, float rx, float ry); }; #endif
you haven't protected .h
file.
you include player.h
in main.cpp
, there gets 1 definition compilation unit. , it's included in player.cpp
, gets sec definition.
if compiler doesn't back upwards #pragma once
, you'll have manually protect them the classical :
#ifndef player_h #define player_h // class definition code here #endif
c++ class constructor header
Comments
Post a Comment