This forum has been archived. All content is frozen. Please use KDE Discuss instead.

build program with simple class

Tags: None
(comma "," separated)
sunaj
Registered Member
Posts
2
Karma
0

build program with simple class

Thu Mar 08, 2012 2:44 pm
Hi,
I've made a new KDevelop c++ project with a main.cpp file.
Then I selected 'create class' and added a simple class.
When I select 'Build selected' I get 'undefined refence to myclass::myclass()'.
What do I need to do to tell KDevelop to compile the class together with the executable?

My code is inserted below.

Thx in advance,
Sunaj

main.cpp
Code: Select all
#include <iostream>
#include "myclass.h"
using namespace std;

int main(int argc, char **argv) {
  myclass mc;
 
  float res = mc.add(3.14,2.14);
  std::cout << "myadd=" << res << std::endl;

  return (0);
}


myclass.h
Code: Select all
class myclass
{

public:
    myclass();
    float add(float a, float b);
};

Code: Select all
myclass.cpp
#include "myclass.h"


float myclass::add(float a, float b) {
  return (a+b);
}
peje
Registered Member
Posts
9
Karma
0
OS

Re: build program with simple class

Thu Mar 08, 2012 7:32 pm
It's what the error says. You have not defined the constructor you declared.

Add

Code: Select all
myclass::myclass()
{
}


to myclass.cpp
sunaj
Registered Member
Posts
2
Karma
0

Re: build program with simple class

Fri Mar 09, 2012 7:52 am
damn - I must be growing blind. Thx.

'The gap between theory and practice is not as wide in theory as it is in practice'


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell