473,385 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

class inheritance and compilation problem. Linux RH6.2. g++

Halo
I have a problem with the following program:

#include <stdlib.h>

struct Base {
int a;
Base() {
a=0;
}
Base(int a): a(a) {};
};

class InherInher;

struct Inher: public Base {
Inher(int a): Base(a) {};
// this is the problem
struct Base* getObj() {
Base *ptr = new InherInher( a );
return ptr;
}
};

struct InherInher: public Inher {
InherInher(int a): Inher( a ) {};
};

main() {
}

Have You got any ideas how to make it work

Greetings
Maciej

Jul 19 '05 #1
3 1746
"Maciej Kwapulinski" <pi****@wp.pl> wrote...
I have a problem with the following program:

#include <stdlib.h>
I don't think you use anything from this header here.

struct Base {
int a;
Base() {
a=0;
}
Base(int a): a(a) {};

Lose the trailing semicolon.
};

class InherInher;

struct Inher: public Base {
Inher(int a): Base(a) {};

Lose the trailing semicolon.


// this is the problem
struct Base* getObj() {
Base *ptr = new InherInher( a );
return ptr;
}
Move it down after the 'InherInher' definition and declare it
inline. Leave only a declaration here:

Base* getObj();
};

struct InherInher: public Inher {
InherInher(int a): Inher( a ) {};
Lose the trailing semicolon.
};
Here is where you move the member definition:

inline Base* Inher::getObj() {
Base *ptr = new InherInher( a );
return ptr;
}

main() {
int main() {
}

Have You got any ideas how to make it work


See above

Victor
Jul 19 '05 #2


Maciej Kwapulinski wrote:
[snip]
Have You got any ideas how to make it work


There is no other way then to move the definition
of function Inher::getObj() past the declaration
of InherInher

....

struct Inher: public Base {
Inher(int a): Base(a) {};
struct Base* getObj();
};

struct InherInher: public Inher {
InherInher(int a): Inher( a ) {};
};

struct Base* Inher::getObj()
{
Base *ptr = new InherInher( a );
return ptr;
}

int main()
{
}

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #3
That's it !!
Great thanks
"Victor Bazarov" <v.********@attAbi.com> wrote in message
news:vg************@corp.supernews.com...
"Maciej Kwapulinski" <pi****@wp.pl> wrote...
I have a problem with the following program:

#include <stdlib.h>


I don't think you use anything from this header here.

struct Base {
int a;
Base() {
a=0;
}
Base(int a): a(a) {};

Lose the trailing semicolon.
};

class InherInher;

struct Inher: public Base {
Inher(int a): Base(a) {};

Lose the trailing semicolon.


// this is the problem
struct Base* getObj() {
Base *ptr = new InherInher( a );
return ptr;
}


Move it down after the 'InherInher' definition and declare it
inline. Leave only a declaration here:

Base* getObj();
};

struct InherInher: public Inher {
InherInher(int a): Inher( a ) {};


Lose the trailing semicolon.
};


Here is where you move the member definition:

inline Base* Inher::getObj() {
Base *ptr = new InherInher( a );
return ptr;
}

main() {


int main() {
}

Have You got any ideas how to make it work


See above

Victor

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tseng, Ling-hua | last post by:
As the comments of the following C++ code, I got the ambiguous error in the specialized class " PThreadTimer<void *(*)(void *)> ". I performed the virtual inheritance mechanism on its base classes...
15
by: Mon | last post by:
I am in the process of reorganizing my code and came across and I came across a problem, as described in the subject line of this posting. I have many classes that have instances of other classes...
3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
4
by: Alex Vinokur | last post by:
Hi, I need something like "function inheritance". typedef void (*func_type1) (int); typedef int (*func_type2) (double); typedef char (*func_type3) (short, int); .... I need a vector...
6
by: mister.mwa | last post by:
Hello, I have the following problem: I have a class Foo, and a class Bar. I want Foo to inherit from Bar, but i want to put them in separate files Foo.vb and Bar.vb. Then i will use the Foo...
0
by: BruinBySea | last post by:
Here is the problem. I built LibA and LibB as class library projects in the same solution as my web application HelloWorldWebApp. Wherever necessary I added project references. Everything...
7
by: Rahul | last post by:
Hi Everyone, I was trying to implement a final class and i start having the destructor of the final class as private, class A { ~A() { printf("destructor invoked\n");
3
by: liam_herron | last post by:
Here is my code: #include <iostream> template<typename T> class RawPtr { protected:
3
by: Al Grant | last post by:
Consider two translation units, (1): namespace { struct S { }; } struct D: S { virtual int f(void); }; and (2): #include <typeinfo> struct D; char const *f(D *p) { return...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.