OOook, lets try this... I'm trying to figure out how to acces class object from a class wihtout trying to acces object of an class from a start.
BTW: good thing is that i've started to comit my time to learing pointers.
anyway... i have 2 cpp files and one h files.
one cpp file is
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include <iostream>
#include "opf.h"
using namespace std;
int main(){
OPF *opf; // accessing the value of memory opf
string danilo="danilo";
opf->name(danilo);
return 0;}
|
which is tester file, the file that i actualy want to compile
second file is .h
1 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
|
#ifndef OPF_H //operative functions
#define OPF_H // operative functions
#include <iostream>
using namespace std;
class OPF { //operative functions
public:
//konstruktor i dekonstruktor
OPF(string &somestring); // activating some string
~OPF(); // deactivating some string
string name(string &somestring);
private:
string str; //deklaracija varijabla
protected:
};
#endif //OPF_H
|
which is a header file that is included in a tester_file.cpp
and at least the other .cpp file
1 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
|
#include "opf.h"
#include <string>
#include <iostream>
using namespace std;
OPF::OPF(string &somestring)
:str(somestring)
{
OPF o;
OPF *opf = &o;
}
string OPF::name(string &somestring)
{
cout<<1<<endl;
str=somestring;
str.resize ( str.size() -4 ); cout<<1<<endl;
str.append ( 1 , ' '); cout<<1<<endl;
return str; cout<<1<<endl;
str.clear(); cout<<1<<endl;
}
OPF::~OPF()
{
OPF o;
OPF *opf = &o;
}
|
which is .cpp file that is part of an opf.h file which is the that cointains all the formulas.
Atleast that is idea.
Im working on Windows, also i don't use IDE, i use notepad++ and GNU with TDC
sooo what is the point :
im trying to use constructor to call the object of its own class, and deconstructor to destory it. [ trying to stop over creating objects of the same class ] and it works.
also im trying [ but don't know if its possible ] to make all of functions from opf.h into one single opf.cpp file. and i'm worring about over creating constructor's objects.
so when i start the program but with single void print_f function it works. But when i start to compile the program above i get multiple errors.
compile cmd code is : g++ -o tester tester_file.cpp opf.h opf.cpp
and the ERROR is :
opf.cpp : in constructor 'OPF:OPF(std:string&)':
opf.cpp:11:6: error: no matching function for call to 'OPF:OPF()'
OPF o;
opf.cpp:11:6: note:candidates are:
in file included from opf.cpp:1:0:
opf.h:12:2:note:OPF::OPF(std::string&)
OPF(string &somestring);
opf.h:12:2: note: candidate expects 1 argument,0 provided
opf.h:8:7: note:OPF::OPF(const OPF&)
class OPF { // operative functions
opf.h:8:7: note: candidate expects 1 argument,0 provided
opf.cpp: indestructor 'OPF:~OPF()':
opf.cpp:27:6: error:no matching function for call to 'OPF::OPF()'
OPF o;
opf.cpp:27:6: note: candidates are
opf.cpp:8:1: note OPF::OPF(std::string &)
OPF::OPF(string &somestring)
opf.cpp:8:1: note: candidate expects 1 argument,0 provided
inf file include from opf.cpp:1:0:
opf.h:8:7: note OPF::OPF(const OPF&)
class OPF { //oper. functions
opf.h:8:7: note: candidate expects 1 argument,0 provided
i was looking at the code for about 2 hours, and can't find solution... any suggestions?
also , as you can see in string OPF::name (string &somestring) there are cout<<1<<endl; several times, i did this because when i loose all the variables in constructor, program alone terminates without error, so i tried looking where is going wrong. So i put 1ones to simulate the steps it does. and i will say that it only loads the first 1.