473,663 Members | 2,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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){cou t <<"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@@QAEX XZ)

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 2055
John Rambo wrote:
//////////////////////// classes_1.cpp
#include <iostream>
#include "classes_1. h"
using namespace std;

A::A():i(0){cou t <<"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.i s.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){cou t <<"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.i s.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*****@hotmai l.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*****@hotmai l.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*****@hotmai l.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
2772
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 am I missing? If that's all, then why did Bjarne even bother adding it to the language? If that's not all, what else can I do with "inline"?
6
3137
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 other right now. Here is my code: template <typename T> class Array { public: Array& operator()(const T& v) {
10
3304
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 -- Christian Staudenmayer
14
2103
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 into a program: /* source1.cpp */ inline int Func(double arg) {
12
11534
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 an associated application, there are the Content-Disposition type options of "inline" or "extension-token". Specifically as regards Internet Explorer, I've tried both inline and the specific filename extension (xls,csv,pdf,doc,...) and the...
3
3142
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 across all browsers, but there seem to be a few very similar solutions, so that is probably not a major hurdle. However, just to complicate things, I want to have it "inline" (http:// www.tizag.com/cssT/inline.php)
17
8368
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 the function if possible" (because if the compiler has the function definition available at an instantiation point, it will estimate whether to inline it or not, and do so if it estimates it would be beneficial, completely regardless of whether...
0
8436
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8771
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8634
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4182
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2000
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.