-2

I have done some research and googling on this error for days, as far as I know this is a common problem for many in c++, I still haven't found a clear answer to this error. I've read that linking the files can fix this, but I could find any example codes to do this. I'am so close to finishing this code, all I need to do to call the constructor from the main file (or just make a simple object), but I keep getting this "unidentified reference to NamedStorm::NamedStorm()" error, please help.

MAIN.CPP

#include <iostream>
#include <string>

#include "NamedStorm.h"

using namespace std;

NamedStorm storm[2];

int main(){
   // NamedStorm Chris("Chris", 70.0, "T.S.", 990.0);
  // storm[0] = Chris;
    return 0;
}

NamedStorm.cpp

// CPP => Function definition
#include <string>

#include "NamedStorm.h"

using namespace std;

// Defining static variables
int NamedStorm::stormCount = 0;

// Constructor definition
NamedStorm::NamedStorm(std::string sName, double wSpeed, std::string sCat, double sPress){
    stormName = sName;
    windSpeed = wSpeed;
    stormCategory = sCat;
    stormPressure = sPress;
    stormCount++;
}

NamedStorm::NamedStorm(std::string sName){
    stormName = sName;
    stormCount++;
}

NamedStorm::NamedStorm(){
    stormName = sName;
    stormCount++;
}

// Destructor definition
//NamedStorm::~NamedStorm(){}

// Get (Accessor) function definition
int NamedStorm::getStormCount(){
    return stormCount;
}

double NamedStorm::getStormPressure(){
    return stormPressure;
}

string NamedStorm::getStormCategory(){
    return stormCategory;
}

string NamedStorm::getName(){
    return stormName;
}

// Set (Mutator) function definition
void NamedStorm::displayOutput(){}
void NamedStorm::sortByNames(){}
void NamedStorm::getAverageStormPressure(){}
void NamedStorm::getAverageWindSpeed(){}
void NamedStorm::getWindSpeed(){}

NamedStorm.h

#ifndef NAMEDSTORM_H_INCLUDED
#define NAMEDSTORM_H_INCLUDED

// NEVER use using namespce in header, use std instead.


class NamedStorm{
private:
    std::string stormName;
    std::string stormCategory;
    double maxWindSpeed;
    double stormPressure;
    static int stormCount;

public:

    // Constructor
    NamedStorm(std::string, double, std::string, double);
    NamedStorm(std::string);
    NamedStorm();

    // Destructor
    //~NamedStorm();

    // Get functions
    int getStormCount();
    double getStormPressure();
    double getWindSpeed();
    std::string getStormCategory();
    std::string getName();

    // Set functions
    static void displayOutput();
    static void sortByNames();
    static void sortByWindSpeed();
    static void getAverageWindSpeed();
    static void getAverageStormPressure();
};

#endif // NAMEDSTORM_H_INCLUDED
hetepeperfan
  • 4,292
  • 1
  • 29
  • 47
Tee-Man
  • 67
  • 2
  • 2
  • 5
  • You need to pass `namedstorm.obj` to linker also. Which toolchain are you using? – greatwolf Jul 27 '13 at 19:20
  • It would be worth **reading** the error message. It's "undefined", not "unidentified". UFOs are unidentified, not symbols. - "but I could find any example codes to do this' - you don't need code - you need a linker and a command line to invoke the linker. –  Jul 27 '13 at 19:20
  • 1
    Compiling and linking is not part of the C++ language. It's specific to the compiler and/or IDE you're using. In short, you need to learn how to use those tools. Read some online tutorials on how to create and build a project in the IDE you're using. ("IDE" is something like Visual Studio, Eclipse, Dev C++, etc.) I'm sure you can even find video tutorials on YouTube on this. – Nikos C. Jul 27 '13 at 19:21
  • Toolchain? You mean the MinGW thing? – Tee-Man Jul 27 '13 at 19:22
  • Yes the MinGW "thing". How are you calling gcc during the linking step? Add the full command to your question. – greatwolf Jul 27 '13 at 19:24
  • I dont know what linking is, that bothers me because I was never told about this in my c++ class. I'll look it up – Tee-Man Jul 27 '13 at 19:28

1 Answers1

0

Why is the definition of the default constructor the same as of the NamedStorm::NamedStorm(std::string) ? I would start from correcting that.

tomi.lee.jones
  • 1,563
  • 1
  • 15
  • 22
  • I did change that constructor, I'm still having the same issue. I believe that the files are in correct position in the project and such. Maybe I'm missing something? – Tee-Man Jul 28 '13 at 16:24