473,715 Members | 2,198 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

namespace,class problem

hello all

GCC gives me this error:

g++ -c -o x-main_a2.o x-main_a2.cpp
g++ -Wall -pedantic -c xfile_a2.cpp
g++ -Wall -pedantic x-main_a2.o xfile_a2.o -o x
Undefined first referenced
symbol in file
xf::Xfile::stat s() x-main_a2.o
ld: fatal: Symbol referencing errors. No output written to x
collect2: ld returned 1 exit status
make: *** [x] Error 1
my programs contain 3 files. here are:

dragon:/home/cstudent/05/052203y/3773/a2> cat xfile_a2.cpp
#include "xfile_a2.h "

namespace xf{
Xfile::Xfile(st ring fname, int maxLineLength, int maxLines){
}
void compress() throw (runtime_error) {

}
void stats() throw (runtime_error) {
}
}

--
dragon:/home/cstudent/05/052203y/3773/a2> cat xfile_a2.h
#include <iostream>
#include <fstream>
#include <string>
#include <stdexcept>
using namespace std;

namespace xf{
class Xfile{

public:

Xfile(string = "mydata", int = 10, int = 10); //constructor
void compress() throw (runtime_error) ;
void stats() throw (runtime_error) ;

private:

typedef char* Xstr;
Xstr* storage_; //an array of array to store the data
int size_; //lines array contains
int length_; //length for each line
};
}
--
dragon:/home/cstudent/05/052203y/3773/a2> cat x-main_a2.cpp
#include <iostream>
using namespace std;
#include "xfile_a2.h "

int main(){
xf::Xfile x;

cout <<"before compressing"<<e ndl;

x.stats();

cout <<"after compressing"<<e ndl;

//x.compress();
//x.stats();

return 0;
}
---
Jul 22 '05 #1
4 1364
Daqian Yang wrote:
hello all

GCC gives me this error:

g++ -c -o x-main_a2.o x-main_a2.cpp
g++ -Wall -pedantic -c xfile_a2.cpp
g++ -Wall -pedantic x-main_a2.o xfile_a2.o -o x
Undefined first referenced
symbol in file
xf::Xfile::stat s() x-main_a2.o
ld: fatal: Symbol referencing errors. No output written to x
collect2: ld returned 1 exit status
make: *** [x] Error 1


You got the wrong linking order. Change it to:

g++ -Wall -pedantic x-file_a2.o xmain_a2.o -o x

Btw, this is off-topic here, since comp.lang.c++ is only about the
language itself, not about any compilers/build tools.

Jul 22 '05 #2
On Tue, 27 Jan 2004 13:42:16 -0400, Daqian Yang wrote:

Change this:
namespace xf{
Xfile::Xfile(st ring fname, int maxLineLength, int maxLines){
}
void compress() throw (runtime_error) {

}
void stats() throw (runtime_error) {
}
}


to:

xf::Xfile::Xfil e(string fname, int maxLineLength, int maxLines){
}

void xf::Xfile::comp ress() throw (runtime_error) {
}

void xf::Xfile::stat s() throw (runtime_error) {
}

This prevents you from accidentally defining new functions (as you did
above) instead of defining the ones in the class that you want.

HTH

- Jay

Jul 22 '05 #3
thx! now it works perfectly!

it makes me better understanding on namespace and class.
"Jay Nabonne" <ja*@rightagain BYTEME.com> wrote in message
news:pa******** *************** *****@rightagai nBYTEME.com...
On Tue, 27 Jan 2004 13:42:16 -0400, Daqian Yang wrote:

Change this:
namespace xf{
Xfile::Xfile(st ring fname, int maxLineLength, int maxLines){
}
void compress() throw (runtime_error) {

}
void stats() throw (runtime_error) {
}
}


to:

xf::Xfile::Xfil e(string fname, int maxLineLength, int maxLines){
}

void xf::Xfile::comp ress() throw (runtime_error) {
}

void xf::Xfile::stat s() throw (runtime_error) {
}

This prevents you from accidentally defining new functions (as you did
above) instead of defining the ones in the class that you want.

HTH

- Jay

Jul 22 '05 #4
hello,

sorry about the off-topic.

jay's solution seems right to my code. :)
"Rolf Magnus" <ra******@t-online.de> wrote in message
news:bv******** *****@news.t-online.com...
Daqian Yang wrote:
hello all

GCC gives me this error:

g++ -c -o x-main_a2.o x-main_a2.cpp
g++ -Wall -pedantic -c xfile_a2.cpp
g++ -Wall -pedantic x-main_a2.o xfile_a2.o -o x
Undefined first referenced
symbol in file
xf::Xfile::stat s() x-main_a2.o
ld: fatal: Symbol referencing errors. No output written to x
collect2: ld returned 1 exit status
make: *** [x] Error 1


You got the wrong linking order. Change it to:

g++ -Wall -pedantic x-file_a2.o xmain_a2.o -o x

Btw, this is off-topic here, since comp.lang.c++ is only about the
language itself, not about any compilers/build tools.

Jul 22 '05 #5

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

Similar topics

7
7436
by: Kevin Newman | last post by:
I've been toying with a namespace manager, and wanted to get some input. So what do you think? if (typeof com == 'undefined') var com = {}; if (!com.unFocus) com.unFocus = {}; com.unFocus.Namespaces = new function() { this.register = function(namespace) { namespace = namespace.split('.');
5
10074
by: Alexis | last post by:
Hello, I have a set of classes I created from schema files using the xsd.exe tool. I'm using namespaces in the clases ( I had to because I have some classes with the same name but not the same class ) Here is how a given class wil looks like. <System.Xml.Serialization.XmlRootAttribute(:="mynamespace", IsNullable:=False)> _ Public Class ClassName
0
2801
by: richwangler | last post by:
This problem should be easily reproducable if anybody has the time. I need to build the following XML programatically and decided to use the XMLSerializer. I simplified the XML (myExample.xml) that i need to create for this post. <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"...
5
2463
by: Mike Oliszewski | last post by:
Given the following c# code: namespace Company2 { public class SomeFunctions { public void FunctionA() { // Do Something. }
10
6655
by: anders | last post by:
I have 2 external assemblies A1 and A2 that both define class X in the global namespace. I need to use both assemblies in my VB project but the names X are ambiguous. How can I get around this problem? Is there a way to refer to the assembly, f.ex. A1.X and A2.X (this syntax does not compile). Or can I change the name X in the Imports directive? Again the problem is how do I refer to the 2 different X'es in assemblies A1 and A2:
4
3083
by: Kevin Newman | last post by:
The primary problem I've had with php is the lack of namespaces, which makes OOP very difficult to organize, since you end up with large number of classes cluttering up the same namespace - which leads to a secondary problem involving php's __autoload feature. Since you cannot specify a namespace when calling a class that may not have been included, you are forced to store all of your classes in the same folder in your file system. This...
4
1699
by: R. Nachtsturm | last post by:
Hi, Question (in short): can i somehow use the namespace tag to define that a class in its own file is actually the subclass (namespace wise) of another class? Explanation: for example, if I have one class named "Schema", this class should have a public sub class named "Table", such as:
5
1444
by: michael.d.pedersen | last post by:
Hello group, I am new to Visual C++ 8 and have a seemingly trivial problem using namespaces. The scenario: I have two classes, TestClass1 and TestClass2, in the namespace Test. I would like to create a reference to TestClass2 in TestClass1; but the compiler doesn't seem to recognize the namespace Test and any classes in it. Here are my class definitions and declarations:
7
2959
by: Armin Zingler | last post by:
Hi all, I have a Form called "Main": Public Class Main Private Sub Button1_Click( _ ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles Button1.Click
8
1893
by: Jack | last post by:
Hi, I have a single class XXX residing in a namspace with the same name: XXX. I can access my class in my code just fine with: XXX.XXX.MySub() '(Note: shared sub!) But I don't want to clutter the code with the namespace every time I access my class.
0
8819
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
8717
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
9330
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
9195
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...
1
9099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6645
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
5966
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
4475
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
3174
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

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.