LinuxQuestions.org
Visit Jeremy's Blog.
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 07-12-2011, 03:41 PM   #1
Loarn
LQ Newbie
 
Registered: Aug 2007
Posts: 2

Rep: Reputation: 0
code substitutions


GNU g++ seems to try to automatically match STL templates to patterns
in your code. E.g. if you code a swap looking function it substitutes
std::swap, is this so or am I inadvertently specifying a template ?
 
Old 07-13-2011, 08:19 AM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,523

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
Avoid specifying "using namespace std" in your code!

Also, you can always reference functions using the :: operator. Here's an example that you can play with:
Code:
#include <algorithm>
#include <iostream>

template <typename T>
void swap(T& x, T& y)
{
   std::cout << "I'm on strike!" << std::endl;
}

int main()
{
   int x = 10;
   int y = 20;

   std::cout << "x = " << x << ", y = " << y << std::endl;

   std::swap(x, y);   // calls the C++ library.

   std::cout << "x = " << x << ", y = " << y << std::endl;

   ::swap(x, y);   // calls the swap() function defined above.

   std::cout << "x = " << x << ", y = " << y << std::endl;
}
 
1 members found this post helpful.
Old 07-14-2011, 06:07 PM   #3
Loarn
LQ Newbie
 
Registered: Aug 2007
Posts: 2

Original Poster
Rep: Reputation: 0
whoops

I(Loarn) was trying to get the compiler to use my code and not what it considered a match
from the template supply, What finally dawned on me, I have been away for awhile, was that
is was not necessarily using the template but since I had #included <algorithm> and was
compiling with the -E flag, it was including the entire algorithm header file in the
assembler stage of the compile.
Thanks for your assistance, please ignore the misspelling I was schooled in the progressive
era.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
string substitutions within a file cleopard Programming 1 09-05-2008 03:52 PM
perl- multiple substitutions on same line gnashley Programming 2 11-12-2007 08:29 AM
variables within sed substitutions? ocicat Programming 3 07-29-2007 12:17 PM
Perl: Using Vars in Substitutions cramer Programming 6 08-26-2006 12:52 PM
sed? -- making substitutions scabies Linux - Software 1 12-21-2003 11:39 PM


All times are GMT -5. The time now is 08:03 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration