473,883 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Constructor problem - help needed urgently to resolve this

Hi,

I have some code from an example, that I want to retrofit into my
project. The code from the example has the following line:

SharedAppenderP tr myAppender( new RollingFileAppe nder("MyAppende r"))
I want to move this line of code to a constructor in a wrapper class, so
that I can determine the appropriate Appender name during the object's
construction.

I have done the ff:

declared a privariate variable in my wrapper class as ff:
SharedAppenderP tr m_Appender ;

In my (wrapper class) constructor, I have the following code:

.....
m_Appender = new RollingFileAppe nder(log_file_n ame)
.....
However, I am getting linking errors (unresolved external symbol). I was
obviously wrong in thinking that I could use copy assignment in this
way. This is the actual liker error I'm getting (Although I am using MS
tools in this instance, I don't believe its a MS specific problem).

Auditor error LNK2019: unresolved external symbol "__declspec(dll import)
public: class log4cplus::help ers::SharedObje ctPtr<class
log4cplus::Appe nder> & __thiscall
log4cplus::help ers::SharedObje ctPtr<class
log4cplus::Appe nder>::operator =(class log4cplus::Appe nder *)"
(__imp_??4?$Sha redObjectPtr@VA ppender@log4cpl us@@@helpers@lo g4cplus@@QAEAAV 012@PAVAppender @2@@Z)
referenced in function "public: __thiscall Auditor::Audito r(int,int)"
(??0Auditor@@QA E@HH@Z)

Any helpful suggestions (or better still, an actual solution to the
problem) will be greatly appreciated.

MTIA

Aug 11 '05 #1
15 3367
* Alfonso Morra:

In my (wrapper class) constructor, I have the following code:

....
m_Appender = new RollingFileAppe nder(log_file_n ame)
....


Don't. Use a constructor initializer list. Initialization is not
assignment.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Aug 11 '05 #2


Alf P. Steinbach wrote:
* Alfonso Morra:
In my (wrapper class) constructor, I have the following code:

....
m_Appender = new RollingFileAppe nder(log_file_n ame)
....

Don't. Use a constructor initializer list. Initialization is not
assignment.


I thoink you're missing the point I'm making. TThe point being this: The
private variable is declared somewhere else (meaning default construct
is invoked). THEN I have to create an instance using the parameters
passed in the constructor. One way round this may be to declare ptrs
return pointers to the objects instead of the objects themselves - just
a guess, I would like to hear from a more experienced C++ person though,
if this is a good way to overcome this issue.

Aug 11 '05 #3
* Alfonso Morra:

Alf P. Steinbach wrote:
* Alfonso Morra:
In my (wrapper class) constructor, I have the following code:

....
m_Appender = new RollingFileAppe nder(log_file_n ame)
....

Don't. Use a constructor initializer list. Initialization is not
assignment.


I thoink you're missing the point I'm making. TThe point being this: The
private variable is declared somewhere else (meaning default construct
is invoked).


Either it's a member variable, or not. If it isn't, make it one. When it
is a member variable, it's only default constructed if you don't initialize
it in a constructor initializer list.

I would like to hear from a more experienced C++ person though,
if this is a good way to overcome this issue.


You already got that.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Aug 11 '05 #4


Alf P. Steinbach wrote:
* Alfonso Morra:
Alf P. Steinbach wrote:

* Alfonso Morra:
In my (wrapper class) constructor, I have the following code:

....
m_Appende r = new RollingFileAppe nder(log_file_n ame)
....
Don't. Use a constructor initializer list. Initialization is not
assignment .

I thoink you're missing the point I'm making. TThe point being this: The
private variable is declared somewhere else (meaning default construct
is invoked).

Either it's a member variable, or not. If it isn't, make it one. When it
is a member variable, it's only default constructed if you don't initialize
it in a constructor initializer list.

I have no doubt that you know what you're talking about. But honestly,
how does a comment such as the one help me to solve my problem?. What I
want to know, is a practical way to solve the problem - possibly, a one
line or two line code/pseudocode segment that show me how to solve the
problem, not generalized theories or rules from the C++ book (as other
people have tended to do). Sure, this may be asking a lot, but if you
don't have the time to answer my "basic questions", then please simply
don't reply to my posts.
I would like to hear from a more experienced C++ person though,
if this is a good way to overcome this issue.

You already got that.


Hear we go with the ego again (sigh) ...

Aug 11 '05 #5

"Alfonso Morra" <sw***********@ the-ring.com> wrote in message
news:dd******** **@nwrdmz01.dmz .ncs.ea.ibs-infra.bt.com...


Alf P. Steinbach wrote:
* Alfonso Morra:
In my (wrapper class) constructor, I have the following code:

....
m_Appender = new RollingFileAppe nder(log_file_n ame)
....

Don't. Use a constructor initializer list. Initialization is not
assignment.


I thoink you're missing the point I'm making. TThe point being this: The
private variable is declared somewhere else (meaning default construct is
invoked). THEN I have to create an instance using the parameters passed in
the constructor. One way round this may be to declare ptrs return pointers
to the objects instead of the objects themselves - just a guess, I would
like to hear from a more experienced C++ person though, if this is a good
way to overcome this issue.


I don't understand what you're saying.

1) You say "the private variable is declared somewhere else". It's a
pointer, declared as a member, right?

2) Whose "default construct" is invoked?

3) And THEN you have to create an instance....of what? If you're creating
an instance of the wrapper, using the parameters passed in its constructor,
then why can't you have an initializer list in that constructor, and create
your member object there?

4) This part I _really_ don't understand: "...to declare ptrs return
pointers to the objects instead of the objects themselves". What's "ptrs"?
What objects? And who's returning something?

5) Perhaps if you showed more of the actual code you're using, we could
figure out where you're doing what, and what might be missing or wrong.
Your one-line code samples and (somewhat vague) descriptions really aren't
giving us enough information.

-Howard

Aug 11 '05 #6
Alfonso Morra wrote:
Auditor error LNK2019: unresolved external symbol "__declspec(dll import)
public: class log4cplus::help ers::SharedObje ctPtr<class
log4cplus::Appe nder> & __thiscall
log4cplus::help ers::SharedObje ctPtr<class
log4cplus::Appe nder>::operator =(class log4cplus::Appe nder *)"
(__imp_??4?$Sha redObjectPtr@VA ppender@log4cpl us@@@helpers@lo g4cplus@@QAEAAV 012@PAVAppender @2@@Z)
referenced in function "public: __thiscall Auditor::Audito r(int,int)"
(??0Auditor@@QA E@HH@Z)

Any helpful suggestions (or better still, an actual solution to the
problem) will be greatly appreciated.

MTIA


Sounds like there is a bug in the library you are using. From the
error
message, it looks like the "log4cplus::hel pers::SharedObj ectPtr" class
declares an assignment operator, but never defines it. Either that, or
you are not linking the correct libraries. You should probably contact
whoever maintains this library and ask them for help.

-shez-

Aug 11 '05 #7
* Alfonso Morra:


Alf P. Steinbach wrote:
* Alfonso Morra:
Alf P. Steinbach wrote:
* Alfonso Morra:
>In my (wrapper class) constructor, I have the following code:
>
>....
>m_Appende r = new RollingFileAppe nder(log_file_n ame)
>....
Don't. Use a constructor initializer list. Initialization is not
assignment .
I thoink you're missing the point I'm making. TThe point being this: The
private variable is declared somewhere else (meaning default construct
is invoked).

Either it's a member variable, or not. If it isn't, make it one. When it
is a member variable, it's only default constructed if you don't initialize
it in a constructor initializer list.

I have no doubt that you know what you're talking about. But honestly,
how does a comment such as the one help me to solve my problem?


You could try it out -- that's what I and others expect.

You should put in some effort yourself, such as at least trying.

What I
want to know, is a practical way to solve the problem - possibly, a one
line or two line code/pseudocode segment that show me how to solve the
problem, not generalized theories or rules from the C++ book (as other
people have tended to do). Sure, this may be asking a lot, but if you
don't have the time to answer my "basic questions", then please simply
don't reply to my posts.


Don't fear, I even help folks who badmouth their helpers instead of trying
anything on their own.

Here's an example of a class using a constructor initializer list instead of
assignment:

class Point
{
private:
int myX;
int myY;
public:
Point( int x, int y ): myX( x ), myY( y ) {}
// other member functions
};

Now try that out, and post some code if you can't get it to work.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Aug 11 '05 #8

"Alfonso Morra" <sw***********@ the-ring.com> wrote in message
news:dd******** **@nwrdmz01.dmz .ncs.ea.ibs-infra.bt.com...
I have done the ff:

declared a privariate variable in my wrapper class as ff:
SharedAppenderP tr m_Appender ;

In my (wrapper class) constructor, I have the following code:

....
m_Appender = new RollingFileAppe nder(log_file_n ame)
....
Assuming your wrapper class is named SharedAppenderP trWrapper you should
initialize m_Appender as bellow:

class SharedAppenderP trWrapper
{
SharedAppenderP tr m_Appender ;
/*other members*/
public:
SharedAppenderP trWrapper(const char *log_file_name) :
m_Appender(new RollingFileAppe nder(log_file_n ame)), -->call it's
constructor instead of calling the assignment operator
/*other initializers*/
{
/*other init code*/
}
/*other methods*/
};

However, I am getting linking errors (unresolved external symbol). I was
obviously wrong in thinking that I could use copy assignment in this
way. This is the actual liker error I'm getting (Although I am using MS
tools in this instance, I don't believe its a MS specific problem).

Auditor error LNK2019: unresolved external symbol "__declspec(dll import)
public: class log4cplus::help ers::SharedObje ctPtr<class
log4cplus::Appe nder> & __thiscall
log4cplus::help ers::SharedObje ctPtr<class
log4cplus::Appe nder>::operator =(class log4cplus::Appe nder *)"
(__imp_??4?$Sha redObjectPtr@VA ppender@log4cpl us@@@helpers@lo g4cplus@@QAEAAV 0
12@PAVAppender@ 2@@Z) referenced in function "public: __thiscall Auditor::Audito r(int,int)"
(??0Auditor@@QA E@HH@Z)

This may be a name resolution issue specific to MSVC since the classes
appear to be in different namespaces.
Any helpful suggestions (or better still, an actual solution to the
problem) will be greatly appreciated.

MTIA

Aug 11 '05 #9


Alf P. Steinbach wrote:
* Alfonso Morra:

Alf P. Steinbach wrote:

* Alfonso Morra:
Alf P. Steinbach wrote:

>* Alfonso Morra:
>
>
>
>>In my (wrapper class) constructor, I have the following code:
>>
>>....
>>m_Appende r = new RollingFileAppe nder(log_file_n ame)
>>....
>
>
>Don't. Use a constructor initializer list. Initialization is not
>assignment .
>

I thoink you're missing the point I'm making. TThe point being this: The
private variable is declared somewhere else (meaning default construct
is invoked).
Either it's a member variable, or not. If it isn't, make it one. When it
is a member variable, it's only default constructed if you don't initialize
it in a constructor initializer list.


I have no doubt that you know what you're talking about. But honestly,
how does a comment such as the one help me to solve my problem?

You could try it out -- that's what I and others expect.

You should put in some effort yourself, such as at least trying.
What I
want to know, is a practical way to solve the problem - possibly, a one
line or two line code/pseudocode segment that show me how to solve the
problem, not generalized theories or rules from the C++ book (as other
people have tended to do). Sure, this may be asking a lot, but if you
don't have the time to answer my "basic questions", then please simply
don't reply to my posts.

Don't fear, I even help folks who badmouth their helpers instead of trying
anything on their own.

Here's an example of a class using a constructor initializer list instead of
assignment:

class Point
{
private:
int myX;
int myY;
public:
Point( int x, int y ): myX( x ), myY( y ) {}
// other member functions
};

Now try that out, and post some code if you can't get it to work.


Didn't mean to get up your nose Alf, and sorry about all the typos,
which probably didn't help my case much either. I am familiar with
constructor initializer list but they won't help (at least I can't see
how they can) in this case.

I am wrapping up the wonderful log4cplus code into a more managable
class. However, there is no documentation (the documentation is the
code) and I am using a provided example as the base of my wrapper class.

Here is the complete code of an example that I am using to write my
wrapper class:

int main( ) {
SharedAppenderP tr myAppender( new RollingFileAppe nder("myLogFile .log")) ;
myAppender->setName("myApp enderName") ;
std::auto_ptr<L ayout> myLayout = std::auto_ptr<L ayout>(new
log4cplus::Patt ernLayout("%d{% Y-%m-%d %a %H:%M:%S} %-5p [%t]: %m%n"));
myAppender->setLayout( myLayout );
Logger myLogger= Logger::getInst ance("myLoggerN ame") ;
myLogger.addApp ender(myAppende r);
myLogger.setLog Level ( INFO_LOG_LEVEL );
myLogger.log( INFO_LOG_LEVEL, "Info Level Message") ;
myLogger.log( TRACE_LOG_LEVEL , "Trace Level Mesage") ;
}

As you can see, the variables are all local variables that go out of
scope after main has ceased. What I am doing is wrapping up the
functionality provided by main, into a wrapper class (lets call this
LogWriter). It is clear from the code above, that I will need variables
(or pointers to objects) of type SharedAppenderP tr, Layout, LogLevel and
Logger at the very least. So armed with these facts, I proced as follows:

class LogWriter {
public:
LogWriter(int,L ogLevel);
virtual ~LogWriter() ;

LogMsg(const string&) ;
setLogLevel(Log Level) ;
...

private:
/* Keep hidden from prying eyes*/
LogWriter(const LogWriter&);
LogWriter& operator=(const LogWriter&);

/* Variables */
SharedAppenderP tr m_Appender ; //Default ctor invoked
log4cplus::tstr ing m_AppenderName ;
log4cplus::tstr ing m_LoggerName ;
log4cplus::tstr ing m_logFilename ;
std::auto_ptr<L ayout> m_Layout ; //Default ctor invoked
LogLevel m_lvl ;
Logger m_Logger ; //Default ctor invoked
bool m_debugOn ;

/*Methods */
log4cplus::tstr ing getLogNameByMod uleId( int ) ;

};
Since we have m_Appender, m_Layout and m_Logger already constructed
(default ctors), I need to know how to "re-create" (for lack of a better
word, so that I can use the variables passed to the ctor of LogWriter. I
(obviously) can't use the code in the example above main() function
verbatim and copy into the ctor of LogWriter, becaue all the variables
will be local to the ctor and after the ctor went out of scope, so will
be the local variables (local to LogWriter::LogW riter()) and all the
private variables will be left unitialised, or at ;least initialised
with values other than that speciifed in the constructor.

So my question then was (and is): how can I initialise my LogWriter
class so that the private variables are assigned the values passed in
the LogWriter ctor? (basically, all I want to do is to replicate the
functionality I havce provided in my main function above.

Armed with some (hopefully more useful information), I hope you will be
able to shed some light on how to solve this - it is not for the lack of
trying, I can assure, you.

MTIA

Aug 11 '05 #10

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

Similar topics

1
719
by: Ron | last post by:
It has been a while since I last programmed in java, I am getting an error trying to instaniate one of my classes, public class teamStats{ String list; public void teamStats(String newlist){ list=newlist; } }
0
1477
by: Kamliesh Nadar | last post by:
Hi I am developing a software using VB.NET I am facing following problems - 1. Though I have placed the NotifyIcon control on the window service application, after starting the service I am not able to view the icon on the system tray. 2. Secondly how to add a new item in the Window explorer
5
1920
by: el prinCipante | last post by:
I'm getting tired of the following error message. Compiler Error message : Error: Need explicit cast to convert from: float to: float * I am trying to use a routine from the Numerical Recipes library called amebsa.c. The routine requires several parameters of the following form. *iter, **p, *yb.... . How does one initialize these variables? If I declare them as pointer (in this case, *yb and *iter) the compiler still tells me that it...
2
3185
by: smanicom | last post by:
Hi all I need help urgently as I am in the middle of a migration and can't resolve a TNS error. My db has been fine for months! Today I connected as sysdba and shut down the db. Now I am trying to bring it back up but when i try connect as sysdba I get ORA-12154: TNS:could not resolve service name This is odd because I have not changed the tnsnames file at all. Please help Am I missing something simple here?
13
2402
by: sam_cit | last post by:
Hi Everyone, I have the following unit to explain the problem that i have, class sample { public : sample() { printf("in sample...\n"); }
1
4937
by: janakivenk | last post by:
Hello, I am running Oracle 10g R2 in our office. I created the following procedure. It is suppose to access an xml file ( family.xml). The procedure is compiled and when I try to run it, i get the following error. SQL> execute domsample('c:\','song.xml','error.txt') BEGIN domsample('c:\','song.xml','error.txt * ERROR at line 1: ORA-31001: Invalid resource handle or path
6
7294
by: =?Utf-8?B?TWF0dA==?= | last post by:
I'm having a problem with a static class constructor being called twice. I have the static class MasterTaskList which uses a BackgroundWorker to execute multiple methods on a separate thread. The static constructor calls a reset function which creates a new instance of BackgroundWorker and attaches the appropriate event handlers. There is also a static method ReportProgress for the called methods to do just that. What is happening is...
1
1470
by: Robert Wells | last post by:
Gentlemen, We are looking for two IBM documents that are needed urgently for a project. They are titled "4680 Store Systems Serial I/O Channel Attachment Information" and "Serial I/O Product Attachment Information". $100 will be paid to the first person to deliver either or both of these documents in their entirety. If you have partial documents or you are not sure please contact US anyway. The contact person is ty@rocketfarm.com ...
5
2962
by: uhdam | last post by:
Hi I am unable to access a non static variable in a static context The variable is an arrayList and in a separate file I cannot change the corresponding non-static class into static class Please help me to resolve this problem
0
9942
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
9792
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
11148
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
10749
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
10857
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,...
0
9577
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...
0
7133
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
5801
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...
2
4223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.