473,785 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

still problem of organize file

Hi all

on last post I confused on how to organize file of class, ok ,the problem
solved : should include class define head on cpp file.
but this time ,still link error:

strange is I put the implement to .h file directly like this:
*******head file*****
class LinuxTestTermin al : public Terminal{
public:
void printch(char ch){
fprintf(stdout, "%c",ch); <--- directly implement here
}
};

there's no error occur;

but when I wrote the .cpp file,(same name as .h file)
*******head file*****
class LinuxTestTermin al : public Terminal{
public:
void printch(char ch);
};

*******cpp file******
#include "LinuxTestTermi nal.h"
void
LinuxTestTermin al::printch(cha r ch){
fprintf(stdout, "%c",ch);
}

error occurs: undefined reference of printch();
What's on earth the problem is?

thank you very much!

key9
completed code here : cygwin enviroment

// test.cpp
// use -lstdc++

#include <stdio.h>
#include <unistd.h>
#include <iostream>

#include "LinuxTerminal. h"

using namespace std;
//this printch function is just for test ,direct use this can pass the test
print
/* void printch(char ch){
fprintf(stdout, "%c",ch);
}
*/
int main(int argc, char *argv[])
{
char q = 'c';

printf("print a new line of doing test");
LinuxTestTermin al* lt = new LinuxTestTermin al();
lt->printch(q);

//printch(q); // direct use this can pass, but lt->printch(q) can not
,why?

while(true); // test perpose loop

}

*************** *************** *****
// Terminal.h

#ifndef __TERMINAL_H_
#define __TERMINAL_H_
class Terminal{ // this is virtual class of terminal
public:

/* <--- comment for test perpose since can not pass the complie
virtual void printch(char) = 0;
virtual void backSpace() = 0;
virtual void printCR() = 0;
virtual void printTab() = 0;
*/

};
#endif // __TERMINAL_H_

*************** *************** *****
// LinuxTerminal.h

#ifndef __LINUXTERMINAL _H_
#define __LINUXTERMINAL _H_

#include "Terminal.h "

class LinuxTestTermin al : public Terminal{
public:

void printch(char ch);
void backSpace();
void printCR();
void printTab();
};
#endif // __LINUXTERMINAL _H_

*************** *************** **********
// LinuxTerminal.c pp

#include "LinuxTestTermi nal.h" // this time, add this line

void
LinuxTestTermin al::printch(cha r ch){
fprintf(stdout, "%c",ch);
}

void
LinuxTestTermin al::backSpace() {
fprintf(stdout, "/b")
}

void
LinuxTestTermin al::printCR(){
fprintf(stdout, "/n");
}

void
LinuxTestTermin al::printTab(){
fprintf(stdout, "/t");
}

May 24 '06 #1
2 1878
key9 wrote:

on last post I confused on how to organize file of class, ok ,the problem
solved : should include class define head on cpp file.
but this time ,still link error:

strange is I put the implement to .h file directly like this:
there's no error occur; error occurs: undefined reference of printch();


Are you sure you link all these files together? Check your compiler's
documentation to learn how to deal with multiple source files.
Jonathan

May 24 '06 #2

"key9" <ia*****@126.co m> wrote in message
news:e5******** **@news.yaako.c om...
Hi all

on last post I confused on how to organize file of class, ok ,the problem
solved : should include class define head on cpp file.
The link problem was NOT because you failed to include the header file in
your source file. If that was the problem, then the .cpp file would fail to
compile, and you'd get a compiler (not link) error.
but this time ,still link error:

strange is I put the implement to .h file directly like this:
*******head file*****
class LinuxTestTermin al : public Terminal{
public:
void printch(char ch){
fprintf(stdout, "%c",ch); <--- directly implement here
}
};

there's no error occur;

but when I wrote the .cpp file,(same name as .h file)
*******head file*****
class LinuxTestTermin al : public Terminal{
public:
void printch(char ch);
};

*******cpp file******
#include "LinuxTestTermi nal.h"
void
LinuxTestTermin al::printch(cha r ch){
fprintf(stdout, "%c",ch);
}

error occurs: undefined reference of printch();
What's on earth the problem is?

thank you very much!

key9


It's the same problem as before. It isn't your code that's the problem,
it's the way you're compiling and linking. When you are compiling and
linking, you're simply failing to include the .cpp file properly. (And when
I say "include", I am referring to making sure the .cpp file compiles and
links properly, NOT whether you're using the preprocessor symbol "#include"
correctly!) You probably just need to specify the .cpp filename somewhere
in the command line (or in your project settings, if you have such a thing).
Read your compiler's documentation on how to compile and link multiple
source files.

-Howard

May 24 '06 #3

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

Similar topics

10
11071
by: Bruce W...1 | last post by:
I've been learning about PHP for a couple of weeks. With includes, PHP scripts, and HTML I can see where a large and complex website could easily turn in to a big hairy mess with files all over the place. Are there any adopted standards, recognized recommendations, or best practices on how all the code should be organized? I haven't found any websites that discuss this. Can anyone point me to information on this? If not then what do...
14
1664
by: Alan Silver | last post by:
Hello, I have spent ages trawling through Google, looking for information about global functions in ASP.NET and I'm still not clear about the best way to go about this (or not). I am writing a site that will be for members only. They will have to log in to gain access to any of the pages. I am holding the user information in an XML file (there will probably never be a large number of user, so this is efficient enough).
3
2153
by: wapsiii | last post by:
Looking for better practise! In a large asp.net project, how is it best to organize classes? When should I create a new project for a class? Is it better to have fewer files with all the classes in or should I put each class in it's own file? Do you put your class files in a certain folder structure?
5
2653
by: CMM | last post by:
I don't seem to "get" ASP.NET 2.0's Localization features. I've read up on everything... and of course, everything is explained in cursory softball terms- not any "real-world" usage way. I hope someone can give me a clue... Questions: 1) Do my eyes deceive me or is it true that localization is still totally utterly disengaged from the Designer and Property Editor... either in source
4
2329
by: Daniel N | last post by:
I am new to .net and want to organize my code better. I am writing in vb.net and the code for my main form is nearing 50-60 pages and would like to create another file like a class, module or code file that SHARE sub procedures, and declarations as if it were with the rest of the code (So I can orginize it in 2 or 3 .vb files). When I create a new class I can;
12
2311
by: Jchick | last post by:
Boy, this should be a simple bit of code but I can't figure out how to make it happen. I have a CSV file shows up in a directory that has 4 fields that need to be printed on labels. Each line of the CSV looks something like this: AcctNo, Name, junk, junk, Address, junk, PhoneNo I need to read each line of the CSV and print them to Avery Label stock
2
3533
by: key9 | last post by:
Hi all look at the organize tree main.c ------ #include lib_adapter.c main() { foo();
6
2201
by: Larry Bud | last post by:
Been working with .net 2 since January, and am in the middle of my first large project. It's becoming obvious that one must organize their code well in a large project to make maintenance easier. So what's your process? Do you stick everything in one Class file? Do you have a separate class file for each "type" of function.. i.e. one for all data access, another for general math, another for string function, etc.
2
2480
by: Fredrik Lundh | last post by:
Dudeja, Rajat wrote: A Python program consists of a script file (the py file you run to start the program), and usually one or more additional module files (py files that you import). The latter can be organized in packages, where appropriate. There's also a search path (sys.path) that you can modify in various ways (including from within the program) if you want to fetch modules from different locations.
0
9484
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
10350
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8983
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7505
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
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
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
4055
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
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
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.