Error Undefined Reference To Constructor
Contents |
here for a quick overview of the site Help Center undefined reference to constructor and destructor Detailed answers to any questions you might have Meta undefined reference to constructor template Discuss the workings and policies of this site About Us Learn more about Stack Overflow undefined reference to constructor in c++ the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x c++ undefined reference to constructor inheritance Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 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
Undefined Reference To Constructor And Destructor C++
I am having is that, when I call a constructor for a class I have 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 Us Learn more about
Undefined Reference To Default Constructor
Stack Overflow the company Business Learn more about hiring developers or posting ads with undefined reference to class c++ us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is c++ undefined reference to class function a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up “Undefined reference” to constructor which is defined up vote 4 down vote favorite I http://stackoverflow.com/questions/15579172/undefined-reference-to-class-constructor-including-cpp-file-fixes 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 = new cpuInput(); Of course I get an error from g++: demo.cpp:15:31: error: http://stackoverflow.com/questions/18173015/undefined-reference-to-constructor-which-is-defined 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 11 '13 at 14:32 delicateLatticeworkFever 7,7341542 2 Sounds like you are not linking to the object file where cpuInput::cpuInput(std::string const &) is defined.
std::allocator
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//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
Get Kubuntu Get Xubuntu Get Lubuntu Get UbuntuStudio Get Mythbuntu Get Edubuntu Get Ubuntu-GNOME Get UbuntuKylin Ubuntu Code of Conduct Ubuntu Wiki Community Wiki Other Support Launchpad Answers Ubuntu IRC Support AskUbuntu Official Documentation User Documentation Social Media Facebook Twitter Useful Links Distrowatch Bugs: Ubuntu PPAs: Ubuntu Web Upd8: Ubuntu OMG! Ubuntu Ubuntu Insights Planet Ubuntu Activity Page Please read before SSO login Advanced Search Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] C++ class constructor not recognized Having an Issue With Posting ? Do you want to help us debug the posting issues ? < is the place to report it, thanks ! Results 1 to 4 of 4 Thread: C++ class constructor not recognized Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode April 26th, 2012 #1 Sissy13 View Profile View Forum Posts Private Message Frothy Coffee! Join Date May 2009 Location Planet Earth Beans 212 DistroXubuntu 12.04 Precise Pangolin C++ class constructor not recognized I'm trying to write a simple test program for the Verse class (a class which I defined). Here is the relevant code: Header file, Verse.h Code: #ifndef VERSE_H #define VERSE_H #include