LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-04-2005, 11:04 AM   #1
ChemicalBurn
LQ Newbie
 
Registered: Feb 2005
Posts: 28

Rep: Reputation: 15
Non-Const reference?


Hi, I have a small problem with calling a function IsEdgeDisjoint, thing is I can call all member functions within the object except this one, I think because of the argument type. I dont know what the problem is, here's the code:

Code:
 bool IsEdgeDisjoint(const Path<NodeTPointer,EdgeTPointer>& otherPath);
This is the prototype for the function in the library,
and here's where Im calling it:
Code:
bool NetworkState::AreEdgeDisjoint(List<LSPEdge> path1, List<LSPEdge> path2){
  
  Path<LSPNode,LSPEdge> Path1;
  Path<LSPNode,LSPEdge> Path2;
  Path1.Edges(path1);
  Path2.Edges(path2);
  cout<<"Path1\n"<<Path1<<endl;
  return Path1.IsEdgeDisjoint(Path2);//This statement Generates the error    
}
But it generates this error:
/home/j_ghibril/GRAPH-v2.0/include/GRAPH/TPP/Path.tpp:284: error: invalid
initialization of non-const reference of type '
GRAPH::List<GRAPH::EdgeT<LSPNodeType, LSPEdgeType>*>&' from a temporary of
type 'GRAPH::List<GRAPH::EdgeT<LSPNodeType, LSPEdgeType>*>'
make: *** [NetworkState.o] Error 1

Anyone have any ideas?
 
Old 04-04-2005, 01:18 PM   #2
Kdr Kane
Member
 
Registered: Jan 2005
Distribution: SUSE, LFS
Posts: 357

Rep: Reputation: 30
Just a suggestion, but it sounds like the preprocessor needs to know about IsEdgeDisjoint before AreEdgeDisjoint.

Make sure your include statements or your declarations are in the correct order.
 
Old 04-04-2005, 02:46 PM   #3
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
It says the error is at:

/home/j_ghibril/GRAPH-v2.0/include/GRAPH/TPP/Path.tpp:284

Which sounds like it is seeing an error in the header that defines your Path template class... Post some code from your IsEdgeDisjoint method, and code around that line of the Path.tpp file.

When using templates, you should understand that unless a template function or class is actually used, it won't be compiled. So, the act of simply using a method that wasn't used before can uncover errors that previously appeared to compile. I'm guessing something like that could be happening here, but I can't say w/o more info.

Last edited by deiussum; 04-04-2005 at 02:48 PM.
 
Old 04-05-2005, 03:54 AM   #4
ChemicalBurn
LQ Newbie
 
Registered: Feb 2005
Posts: 28

Original Poster
Rep: Reputation: 15
Im pretty sure the included file is fine, because it did compile it before when I used other functions in the class, but its this function specifically that is giving the error.
And sorry I forgot to mention, the error at line 284 is actuall the last line in the class (new line nothing in it) Thats why im confused. Though I was wondering about the meaning of the error "non-const reference" when does it usually come out?

@Kane, thanks for the tip, but I checked the header files, they were in proper order, but I switched the Path.h up to the top but still...

Last edited by ChemicalBurn; 04-05-2005 at 04:02 AM.
 
Old 04-05-2005, 08:32 AM   #5
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Here's one example of a small program that can generate the non-const error you are seeing.

Code:
#include <iostream>
using namespace std;

class A
{
    public:
        A() {}
};


int main()
{
    A& a = NULL;

    return 0;
}
And here is a program that demonstrates what I was talking about with template classes and functions not getting compiled unless those specific functions are used

Code:
#include <iostream>
using namespace std;

template <typename T>
void Blah (T t)
{
    // Obvious compiler error here since a is not
    // declared anywhere.  Won't generate any errors
    // Unless the Blah function is called, though!!
    cout << t << a << endl;
}

int main()
{
    // Uncomment and the errors appear, leave commented
    // and no errors are reported because the Blah function
    // doesn't really get compiled

    //Blah(2);

    return 0;
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++: #define OR const int ? Hady Programming 5 10-07-2005 11:43 AM
c++ ERROR: int to const char ashirazi Programming 6 08-06-2004 10:01 PM
const in C++ lazyboy0001 Programming 5 04-08-2004 04:43 PM
Saving an Ip to a Const? Half_Elf Linux - Networking 3 07-12-2002 08:20 PM
conversion to non-const reference type max2878 Linux - General 2 05-23-2002 01:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration