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

Module pass the compile but can not us in main()

Hi All

I defined a class "RootElement"
And want the class can be inherit tree's root.

The main idea is using std::string as the "config" of the instance
the module pass the compile with the help of kindness guys here,but when I
put it in main() , it can not work
Here's the code

*********************************************//root_element.hpp
#ifndef _ROOTELEMENT_
#define _ROOTELEMENT_

#include <string>

class RootElement{

public:
/* just for operate overload */
virtual
RootElement& operator<< (std::string& str);

public:
/* overloadable function open to user*/
// PS: & means reference , change this will dieectly change to obj

/* in */
//accept input string
int acceptiStr(const std::string& istr);

// check input string is legal
int checkiStr(const std::string& istr);

/* out */
virtual std::string outputoStr();
protected:
/*me and my son can use it ,user can not!*/

// any string , just check it! 0 - OK , 1 - error
virtual
int chkiStr(const std::string& istr);

// str must be correct ,must be error check before using
virtual
int hndValidiStr(const std::string& istr);

protected:

// check single pos , inherit that we can simply define one way in our son
virtual
int chkEachiStr(const std::string& istr);

// give out an way can simply handler string's 1 char
virtual
int hndEachiStr(const std::string& istr);

};

#endif /* _ROOTELEMENT_ */

**************************************//root_element.cpp

#include <iostream>
#include "root_element.hpp"
#include <sstream>

RootElement&
RootElement::
operator<< (std::string& str)
{
std::stringstream Temp;
Temp << str;
acceptiStr(Temp.str ());

}

int
RootElement::
acceptiStr(const std::string& istr)
{
if (chkiStr(istr)){
hndValidiStr(istr);
return 0;
}
else{
return 1;
}
}

int
RootElement::
chkiStr(const std::string& istr)
{

std::string::size_type sz_;
std::string::size_type sz_E;

std::string temp_str;

sz_E = istr.length();

sz_ = 0;

while( sz_ != sz_E ){
temp_str = istr.at(sz_);
if (chkEachiStr(temp_str)){
sz_ ++;
}
else
return 1;
}

return 0;
}

int
RootElement::
hndValidiStr(const std::string& istr)
{
std::string::size_type sz_;
std::string::size_type sz_E;

std::string temp_str;

sz_E = istr.length();

for (sz_ = 0; sz_ != sz_E ; sz_++){
temp_str = istr.at(sz_);
hndEachiStr(temp_str);

}

return 0;

}

int
RootElement::
hndEachiStr(const std::string& istr){
std::cout <<" RootElement: hndEachiStr is running! " << std::endl;

}
//testmain.cpp************************************** *************
#include<iostream>
#include<string>
#include "root_element.hpp"
using namespace std;

RootElement re_;

int main(int argc, char* argv[])
{

string str = " This is test sample";
re_ << str;
return 0;
}

Thank you very much!

key9
Nov 25 '06 #1
8 1448

key9 wrote:
Hi All

I defined a class "RootElement"
And want the class can be inherit tree's root.

The main idea is using std::string as the "config" of the instance
the module pass the compile with the help of kindness guys here,but when I
Some of your functions don't have proper return values. It would be
interesting to know what compiler and settings you have not to catch
this or at least warn

Some of your functions are declared but not defined AFAICS.

regards
Andy Little

Nov 25 '06 #2
Some of your functions don't have proper return values. It would be
interesting to know what compiler and settings you have not to catch
this or at least warn
$ g++ -v
Using built-in specs.
Target: i486-linux-gnu
Configured with:
.../src/configure -v --enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --enable-nls --program-suffix=-4.0 --enable-__cxa_atexit
--enable-clocale=gnu --enable-libstdcxx-debug --enable-java-awt=gtk-default
--enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre
--enable-mpfr --disable-werror --with-tune=pentium4 --enable-checking=release
i486-linux-gnu
Thread model: posix
gcc version 4.0.3 (Ubuntu 4.0.3-1ubuntu5)

$ g++ -c root_element.cpp

$ ls
root_element.hpp semantic.cache test.cpp
root_element.cpp root_element.o

$ g++ -o test1 test.cpp root_element.o
root_element.o:(.gnu.linkonce.r._ZTV11RootElement[vtable for
RootElement]+0xc): undefined reference to `RootElement::outputoStr()'
root_element.o:(.gnu.linkonce.r._ZTV11RootElement[vtable for
RootElement]+0x18): undefined reference to
`RootElement::chkEachiStr(std::basic_string<char, std::char_traits<char>,
std::allocator<char const&)'
collect2: ld returned 1 exit status

and if I declear a function in hpp , am I must defined it in cpp? no matter
it performance a NOP operation?

Nov 25 '06 #3

key9 wrote:
Some of your functions don't have proper return values. It would be
interesting to know what compiler and settings you have not to catch
this or at least warn

$ g++ -v
Using built-in specs.
Target: i486-linux-gnu
Configured with:
../src/configure -v --enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --enable-nls --program-suffix=-4.0 --enable-__cxa_atexit
--enable-clocale=gnu --enable-libstdcxx-debug --enable-java-awt=gtk-default
--enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre
--enable-mpfr --disable-werror --with-tune=pentium4 --enable-checking=release
i486-linux-gnu
Thread model: posix
gcc version 4.0.3 (Ubuntu 4.0.3-1ubuntu5)

$ g++ -c root_element.cpp
Try g++ -Wall -c myfile.cpp

This should output some warnings and you should modify the code to get
rid of those.
$ ls
root_element.hpp semantic.cache test.cpp
root_element.cpp root_element.o

$ g++ -o test1 test.cpp root_element.o
root_element.o:(.gnu.linkonce.r._ZTV11RootElement[vtable for
RootElement]+0xc): undefined reference to `RootElement::outputoStr()'
root_element.o:(.gnu.linkonce.r._ZTV11RootElement[vtable for
RootElement]+0x18): undefined reference to
`RootElement::chkEachiStr(std::basic_string<char, std::char_traits<char>,
std::allocator<char const&)'
collect2: ld returned 1 exit status

and if I declear a function in hpp , am I must defined it in cpp? no matter
it performance a NOP operation?
Yes that is what the "undefined reference" messages are saying. You can
also define them inline in the header, but if used they must be
defined.

regards
Andy Little

Nov 25 '06 #4
key9 wrote:
Hi All

I defined a class "RootElement"
And want the class can be inherit tree's root.

The main idea is using std::string as the "config" of the instance
the module pass the compile with the help of kindness guys here,but when I
put it in main() , it can not work
What errors are you getting? What results (if any) did you get, and how
did they differ from what you expected?

If you don't provide us that info, how do you expect us to help you?
Here's the code

*********************************************//root_element.hpp
#ifndef _ROOTELEMENT_
#define _ROOTELEMENT_
Read my previous post. This is still illegal. Any identifier with a
leading underscore followed by an upper case letter is reserved to the
impplementation.

[remainder redacted]
Nov 25 '06 #5
Thank , all folks :-)

only little experience of VB coding , just beginner of c/cpp ;
no actually c/c++ coding experience.

I found my mistake exist on grammar and misspell.and stipulation of coding,
just like these 2 lines:
#ifndef _ROOTELEMENT_ <--- what on earth I should use? and why?
#define _ROOTELEMENT_
any document or suggest?
Nov 25 '06 #6
key9 wrote:
Thank , all folks :-)

only little experience of VB coding , just beginner of c/cpp ;
no actually c/c++ coding experience.

I found my mistake exist on grammar and misspell.and stipulation of coding,
just like these 2 lines:
>#ifndef _ROOTELEMENT_ <--- what on earth I should use? and why?
#define _ROOTELEMENT_

any document or suggest?

Something predictable and unlikely to be used for
something else.

I use
#ifdef INCLUDED_MYINCLUDEFILE_H

where the file name is myincludefile.h
Nov 25 '06 #7
key9 wrote:
Thank , all folks :-)

only little experience of VB coding , just beginner of c/cpp ;
no actually c/c++ coding experience.

I found my mistake exist on grammar and misspell.and stipulation of coding,
just like these 2 lines:
>#ifndef _ROOTELEMENT_ <--- what on earth I should use? and why?
#define _ROOTELEMENT_

any document or suggest?

Something predictable and unlikely to be used for
something else.

I use
#ifdef INCLUDED_MYINCLUDEFILE_H

where the file name is myincludefile.h
Nov 25 '06 #8

key9 wrote in message ...
>Thank , all folks :-)

only little experience of VB coding , just beginner of c/cpp ;
no actually c/c++ coding experience.

I found my mistake exist on grammar and misspell.and stipulation of coding,
just like these 2 lines:
>#ifndef _ROOTELEMENT_ <--- what on earth I should use? and why?
#define _ROOTELEMENT_

any document or suggest?
Common practice is to use:

// file: RootElement.h purpose: define class RootElement
#ifndef ROOTELEMENT_H
#define ROOTELEMENT_H
// .....
#endif // #ifndef ROOTELEMENT_H

The people who write the compilers need some variables, and they need
insurance that the end user won't change the values. So, they reserved a
certain nameing convention for their use (leading underscore(s)). If you
never start a name with an underscore, you will not have a conflict (there
are times when you can use underscores, but, until you know when/where it's
best to just not use them.)

--
Bob R
POVrookie
Nov 25 '06 #9

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

Similar topics

5
by: dody suria wijaya | last post by:
I found this problem when trying to split a module into two. Here's an example: ============== #Module a (a.py): from b import * class Main: pass ============== ==============
110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
2
by: rh0dium | last post by:
Hi all, So I have a slice of code which calls other python code. I have started to take a real liking to the logging module, but I want to extend this into the called python code. I have no...
11
by: Steve | last post by:
Hi All, I'm having a tough time converting the following regex.compile patterns into the new re.compile format. There is also a differences in the regsub.sub() vs. re.sub() Could anyone lend...
3
by: johnny | last post by:
Can a class inside a module, access a method, outside of class, but inside of the module? Eg. Can instance of class a access main, if so how? What is the scope of "def main()" interms of class...
3
by: Mitko Haralanov | last post by:
For various reason, what I need to do is be able to send some Python code (mostly entire functions in the form of a string) to a remote server (written in Python), have that server compile the code...
5
by: Gruik | last post by:
Hi people, I'm currently working on python embedding with C++. My goal is that the C++ part handle files writing/reading so that the Python part only works with buffers. I succeeded in buffer...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
9
by: YouCanCallMeAl | last post by:
It seems that the multiprocessing module in 2.6 is broken for *BSD; I've seen issue 3770 regarding this. I'm curious if there are more details on this issue since the posts in 3770 were a bit...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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...
0
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,...
0
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...
0
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,...

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.