Linker Error Undefined Reference To Class Constructor
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions undefined reference to constructor and destructor c++ you might have Meta Discuss the workings and policies of undefined reference to default constructor this site About Us Learn more about Stack Overflow the company Business Learn more about hiring undefined reference to class c++ developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a c++ undefined reference to class function community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Undefined reference to class constructor, including .cpp file fixes up vote 14 down vote favorite 1 The problem I am having is that, when I call a constructor for a class I have
Undefined Reference To Constructor Template
created I get the following error. main.cpp:20: undefined reference to `StaticObject::StaticObject(Graphics*, sf::String, sf::Vector2)' This problem can be 'fixed' adding an include for the .cpp file in main.cpp like so. ... #include "GameObjects/StaticObject.cpp" ... Although this solves the problem, this seems like a poor solution and goes against what I have been previously told. Is there any other way to solve this problem? I'm using Netbeans 7.3 with g++ to code/compile this program. Below is the relevant code. main.cpp ... #include
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About
C++ Undefined Reference To Constructor Inheritance
Us Learn more about Stack Overflow the company Business Learn more about hiring c++ undefined reference to superclass constructor developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the c++ undefined reference to destructor Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up “Undefined reference” to constructor which is http://stackoverflow.com/questions/15579172/undefined-reference-to-class-constructor-including-cpp-file-fixes defined up vote 4 down vote favorite I have a constructor whose signature is this: cpuInput (const std::string &label); The actual constructor uses an initialization list referencing a superconstructor, so it looks like this: cpuInput::cpuInput (const string &label) : StateMonitor::input(label) { } The class compiles fine as an object file. If I compile that file together with a driver that invokes the constructor: cpuInput *cpu = http://stackoverflow.com/questions/18173015/undefined-reference-to-constructor-which-is-defined new cpuInput(); Of course I get an error from g++: demo.cpp:15:31: error: no matching function for call to ‘cpuInput::cpuInput()’ demo.cpp:15:31: note: candidates are: In file included from demo.cpp:3:0: input_cpusage/cpuInput.hpp:7:3: note: cpuInput::cpuInput(const string&) Now here's the strange part: if I change the constructor call to: cpuInput *cpu = new cpuInput("cpu"); And leave everything else the same, I now get: demo.cpp:15: undefined reference to `cpuInput::cpuInput(std::string const&)' I realize that const string& is not quite the same as string const&, but I had thought this was the standard way of passing a string reference (in this case, via conversion from a const char*) in C++, and this: class A { public: A (const string &s) : x(s) { cout << x << endl; } private: const string x; }; class B : A { public: B (const string &s) : A(s) { } }; int main (void) { new B("test"); return 0; } Does NOT reproduce the issue, although it seems identical WRT the relevent elements to me. So why on the one hand would g++ say: candidates are ... cpuInput::cpuInput(const string&) Then to new cpuInput("string") say: undefined reference to `cpuInput::cpuInput(std::string const&)' c++ g++ share|improve this question asked Aug 1
std::allocator
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
http://www.dreamincode.net/forums/topic/257873-undefined-references-to-constructors-and-destructors/ //strSet.h #ifndef _STRSET_ #define _STRSET_ #include
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// strSet.cpp #include
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// setcalc.cpp #include
Pages) 1 2 → New Topic/Question Reply 15 Replies - 9855 Views - Last Post: 02 December 2011 - 10:11 AM Rate Topic: #1 Crimson Wings D.I.C Head Reputation: 13 Posts: 215 Joined: 11-July 09 Undefined References to Constructors and Destructors. Posted 30 November 2011 - 03:38 PM I have the following files: Leomedia.h #include "MusicMetaDatter.h" #ifndef LEOMEDIA_H #define LEOMEDIA_H namespace Leomedia { typedef enum { read, write } FileMode; } #endif // LEOMEDIA_H MusicMetaDatter.h #ifndef MUSICMETADATTER_H #define MUSICMETADATTER_H #include "Leomedia.h" /** * METADATTER * @Version 1.0.0a * @Author: Sergio Andrés Ibañez (Leonnears) * @Twitter: Leonnears * @Package: Leomedia */ namespace Leomedia { typedef enum { mp3, m4a, flac, ape, wavPack, aiff, wav, ogg, tta } AudioFileType; class MusicMetaDatter { public: MusicMetaDatter(std::string fileName, AudioFileType type, FileMode mode); virtual ~MusicMetaDatter(); private: std::string md_fileName; AudioFileType md_fileType; FileMode md_fileMode; }; } #endif // MUSICMETADATTER_H MusicMetaDatter.cpp #include "MusicMetaDatter.h" MusicMetaDatter::MusicMetaDatter(std::string fileName, AudioFileType type, FileMode mode) { this -> md_FileName = fileName; this -> md_fileType = type; this -> md_fileMode = mode; } MusicMetaDatter::~MusicMetaDatter() { //dtor } MetaDatterTest #include