473,327 Members | 2,071 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,327 software developers and data experts.

problem with "inline"

Hi, I made the following test program:
//////////////////////// classes_1.cpp
#include <iostream>
#include "classes_1.h"
using namespace std;

A::A():i(0){cout <<"const A: i =" << i <<endl;}
A::~A(){cout <<"destr A"<<endl;}
inline void A::showA() {cout << "show A: i =" << i <<endl;};
//////////////////////// classes_1.h
#ifndef A_H
#define A_H
class A{
int i;
public:
void set(int ii){i=ii;}
inline void showA();
A();
~A();};
#endif
////////////////////////
and a simple "main.cpp" file which makes an A object , sets an i and shows
it.

It compiles without problems, but I have the following link-error:
->error LNK2001: unresolved external symbol "public: void __thiscall
A::showA(void)" (?showA@A@@QAEXXZ)

when I remove both the inlines I don't have a link-error .

What am I doing wrong ??

Thanks in advance.

Jul 22 '05 #1
9 2011
John Rambo wrote:
//////////////////////// classes_1.cpp
#include <iostream>
#include "classes_1.h"
using namespace std;

A::A():i(0){cout <<"const A: i =" << i <<endl;}
A::~A(){cout <<"destr A"<<endl;}
inline void A::showA() {cout << "show A: i =" << i <<endl;};
//////////////////////// classes_1.h
#ifndef A_H
#define A_H
class A{
int i;
public:
void set(int ii){i=ii;}
inline void showA();
A();
~A();};
#endif
////////////////////////
and a simple "main.cpp" file which makes an A object , sets an i and shows
it.

It compiles without problems, but I have the following link-error:

[...]

Move the implementation of the inline function from classes_1.cpp to
classes_1.h

HTH,

Niels Dekker
www.xs4all.nl/~nd/dekkerware
Jul 22 '05 #2
Thanks, but isn't it possible to place the implementation in the cpp file
(otherwise I have problems with the "using namespace std" which may not be
placed in the header file...) ???

"Niels Dekker - no reply address" <un*****@this.is.invalid> wrote in message
news:41***************@this.is.invalid...
John Rambo wrote:
//////////////////////// classes_1.cpp
#include <iostream>
#include "classes_1.h"
using namespace std;

A::A():i(0){cout <<"const A: i =" << i <<endl;}
A::~A(){cout <<"destr A"<<endl;}
inline void A::showA() {cout << "show A: i =" << i <<endl;};
//////////////////////// classes_1.h
#ifndef A_H
#define A_H
class A{
int i;
public:
void set(int ii){i=ii;}
inline void showA();
A();
~A();};
#endif
////////////////////////
and a simple "main.cpp" file which makes an A object , sets an i and shows it.

It compiles without problems, but I have the following link-error:

[...]

Move the implementation of the inline function from classes_1.cpp to
classes_1.h

HTH,

Niels Dekker
www.xs4all.nl/~nd/dekkerware

Jul 22 '05 #3
John Rambo wrote:

#include <iostream>
#include "classes_1.h"
using namespace std;

inline void A::showA() {cout << "show A: i =" << i <<endl;};
I wrote: Move the implementation of the inline function from classes_1.cpp to
classes_1.h
John Rambo wrote: Thanks, but isn't it possible to place the implementation in the cpp file
Not if you want your member function to be "inline".
(otherwise I have problems with the "using namespace std" which may not be
placed in the header file...) ???


That's a good point. But you don't need the "using namespace std", if
you do "std::"! As follows:

#include <iostream>
inline void A::showA() {std::cout << "show A: i =" << i <<
std::endl;};
Niels Dekker
www.xs4all.nl/~nd/dekkerware
Jul 22 '05 #4
Ok. Thanks a lot; I have still a question, however:
how can I tell the compiler that it is the std-version of << I want to use
?? "using std::<<;" doesn't works .

"Niels Dekker - no reply address" <un*****@this.is.invalid> wrote in message
news:41***************@this.is.invalid...
John Rambo wrote:

#include <iostream>
#include "classes_1.h"
using namespace std;

inline void A::showA() {cout << "show A: i =" << i <<endl;};
I wrote:
Move the implementation of the inline function from classes_1.cpp to
classes_1.h


John Rambo wrote:
Thanks, but isn't it possible to place the implementation in the cpp file
Not if you want your member function to be "inline".
(otherwise I have problems with the "using namespace std" which may not

be placed in the header file...) ???


That's a good point. But you don't need the "using namespace std", if
you do "std::"! As follows:

#include <iostream>
inline void A::showA() {std::cout << "show A: i =" << i <<
std::endl;};
Niels Dekker
www.xs4all.nl/~nd/dekkerware

Jul 22 '05 #5
Please don't top-post. Rearranged.

John Rambo wrote:
John Rambo wrote:
> Thanks, but isn't it possible to place the implementation in the
> cpp file


Not if you want your member function to be "inline".
> (otherwise I have problems with the "using namespace std" which
> may not be placed in the header file...) ???


That's a good point. But you don't need the "using namespace std",
if you do "std::"! As follows:

#include <iostream>
inline void A::showA() {std::cout << "show A: i =" << i <<
std::endl;};


Ok. Thanks a lot; I have still a question, however:
how can I tell the compiler that it is the std-version of << I want to
use ?? "using std::<<;" doesn't works .


Why would you need that?
Jul 22 '05 #6
found it: "std::operator<<"

"Rolf Magnus" <ra******@t-online.de> wrote in message
news:cf*************@news.t-online.com...
Please don't top-post. Rearranged.

John Rambo wrote:
John Rambo wrote:
> Thanks, but isn't it possible to place the implementation in the
> cpp file

Not if you want your member function to be "inline".

> (otherwise I have problems with the "using namespace std" which
> may not be placed in the header file...) ???

That's a good point. But you don't need the "using namespace std",
if you do "std::"! As follows:

#include <iostream>
inline void A::showA() {std::cout << "show A: i =" << i <<
std::endl;};


Ok. Thanks a lot; I have still a question, however:
how can I tell the compiler that it is the std-version of << I want to
use ?? "using std::<<;" doesn't works .


Why would you need that?

Jul 22 '05 #7
On Sat, 14 Aug 2004 18:45:16 GMT, John Rambo <Ia*****@hotmail.com> wrote:
found it: "std::operator<<"


It's very unlikely that you would need that.

std::cout << "hello\n";

That works perfectly well because C++ has a rule (sometimes called Koenig
lookup) which says that if the type of an argument to a particular
function or operator is in a particular namespace then that namespace is
searched automatically. So type type of cout is in the std namespace
(std::ostream), so you don't need to tell the compiler to look for
operator<< in the std namesapce.

john
Jul 22 '05 #8
On Sat, 14 Aug 2004 15:28:49 GMT, "John Rambo" <Ia*****@hotmail.com>
wrote:
Ok. Thanks a lot; I have still a question, however:
how can I tell the compiler that it is the std-version of << I want to use
?? "using std::<<;" doesn't works .

If you really need to do that then try:
using std::operator<<

rossum
--

The ultimate truth is that there is no Ultimate Truth
Jul 22 '05 #9
"John Harrison" <jo*************@hotmail.com> wrote:
On Sat, 14 Aug 2004 18:45:16 GMT, John Rambo <Ia*****@hotmail.com> wrote:
found it: "std::operator<<"


It's very unlikely that you would need that.

std::cout << "hello\n";

That works perfectly well because C++ has a rule (sometimes called Koenig
lookup) which says that if the type of an argument to a particular
function or operator is in a particular namespace then that namespace is
searched automatically.


I suppose he wanted to guard against something like:

// in header
namespace foo
{
std::ostream &operator<<(std::ostream &, char const *);
};

// in non-header
using namespace foo;
int bar()
{
std::cout << "hello\n";
}
};

(but I would expect the compiler to complain about ambiguous
function)
Jul 22 '05 #10

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

Similar topics

14
by: Chris Mantoulidis | last post by:
I am not clear with the use of the keyword inline... I believe you add it do a function when you implement the function inside the header file where the class is stored... But is that all? What...
6
by: Mattias Brändström | last post by:
Hello all! I am trying to write code that allows me to initialise one of my classes inline (with a vector like structure). Inline might not be the best term to use here but I can't think of any...
10
by: Christian Staudenmayer | last post by:
Hi, is there any revision of the C standard that allows the "inline" keyword (or a similar feature)? I know it is possible in gcc, but then it might be a gcc feature only. Greetings, Chris ...
14
by: Frederick Gotham | last post by:
The original purpose of "inline" was that code could be "expanded in place". Of course, it has other uses... For one thing, the following two translation units will compile together succesfully...
12
by: Dave H. | last post by:
Please redirect me if this message is posted to the wrong group. Given the intention of delivering content to an HTTP user agent (such as Internet Explorer) which is to be immediately opened by...
3
by: Baron Samedi | last post by:
I am looking for a reliable cross-browser pull-quote solution in CSS. See for instance, http://www.sitepoint.com/examples/pullquotes/ The problem seems at first to be sure that it functions...
17
by: Juha Nieminen | last post by:
As we know, the keyword "inline" is a bit misleading because its meaning has changed in practice. In most modern compilers it has completely lost its meaning of "a hint for the compiler to inline...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.